Simoona's back-end is built using ASP.NET with Entity Framework. Project dependencies are managed via NuGet.
- Open the solution file
Shrooms.sln
file located insrc\api\Shrooms.sln
. - Set
Shrooms.Presentation.Api
project as StartUp project (located insrc\api\Main\PresentationLayer\Shrooms.Presentation.Api\
). - Start it with debug (F5) or without debug (Ctrl+F5).
- Wait for project to build.
- If database is set up and Web.config has correct connection string the project should start. To set up the database head over to build folder.
Simoona uses email sending services to send its users various important and optional notifications. If you don't set up the mailing service, users won't be able to receive these notifications. It's especially important to set it up if local sign-up/sign-in system is being used (by default it is), because the system uses email service to send information about verifying email addresses and resetting passwords. For development purposes the easiest way to set up SMTP Server is to use MailTrap. For sending emails to their destinations we recommend services like SendGrid.
Follow these steps to configure mail sending service in Simoona:
-
Create a service account using MailTrap, SendGrid or any other email service
-
After creating an account find your SMTP server credentials on their website
-
Open Web.config file located in
src\api\Main\PresentationLayer\Shrooms.Presentation.Api\Web.config
-
Locate
<mailSettings>
block in Web.config file and paste your credentials and host to appropriate places inside of<network>
block as shown in code snippet bellow<system.net> <mailSettings> <smtp from="[email protected]"> <network host="yourHost" userName="yourUserName" password="yourPassword" /> </smtp> </mailSettings> </system.net>
Another way to work with email services while developing is installing smtp4dev and setting your Web.config
according to this:
```xml
<system.net>
<mailSettings>
<smtp from="[email protected]">
<network host="localhost" port="25" />
</smtp>
</mailSettings>
</system.net>
```
You will see all your sent emails in the dedicated application on your local machine while actually no third party or online service is involved.
All configurable properties are located in src\api\Main\PresentationLayer\Shrooms.Presentation.Api\Web.config
file.
Don't forget to change API and Client urls if running on different addresses:
<!-- Url used to redirect back to AngularJS application after external login -->
<add key="OAuthRedirectUri" value="http://localhost:3000/" />
<!-- Urls for AngularJS application and API -->
<add key="ClientUrl" value="http://localhost:3000/" />
<add key="ApiUrl" value="http://localhost:50321" />
By default Simoona uses local file system storage, but it's possible to use Azure Blob Storage for storing media files. To set up blob storage follow these steps:
-
Head over to Azure Portal and follow instructions Azure Quickstart
-
After creating blob storage get its connection string
-
Open
Web.config
file located insrc\api\Main\PresentationLayer\Shrooms.Presentation.Api\
-
Locate
<connectionStrings>
block and put your blob storage connection string as a value ofconnectionString
inside<add>
block withStorageConnectionString
name as shown below<connectionStrings> ... <add name="StorageConnectionString" connectionString="yourConnectionString" /> </connectionStrings>
If you don't use ImageResizer Performance Edition plugins, but wish to use Azure Blob Storage you will need to follow these extra steps:
-
Open Web.config file located in
src\api\Main\PresentationLayer\Shrooms.Presentation.Api\Web.config
-
Inside
<rules>
block in<system.webServer>
block findRedirect to Azure Blob Storage
rule, make sure that it is uncommented and paste your blob storage url asurl
value inside<action>
block as shown bellow (make sure to leave{R:1}
intact)<system.webServer> <rewrite> <rules> <rule name="Redirect to Azure Blob Storage"> <match url="^storage/(.*)$"/> <action type="Redirect" url="https://your-project.blob.core.windows.net/{R:1}" redirectType="Permanent" /> </rule> </rules> </rewrite> </system.webServer>
Simoona supports sign in with Google and Facebook. To enable this feature follow these steps:
- Get Google and/or Facebook application credentials
- Open Web.config file located in
src\api\Main\PresentationLayer\Shrooms.Presentation.Api\
- Locate
<appSettings>
block and find the lines shown below and just paste your application credentials to appropriate places asvalue
<appSettings>
...
<add key="GoogleAccountClientId" value="yourGoogleAccountClientId" />
<add key="GoogleAccountClientSecret" value="yourGoogleAccountClientSecret" />
<add key="FacebookAccountAppId" value="yourFacebookAccountAppId" />
<add key="FacebookAccountAppSecret" value="yourFacebookAccountAppSecret" />
...
</appSettings>
Simoona can also leverage ImageResizer Performance plugins to make media delivery faster. If you wish to try these plugins in development environment or you have a license to use them follow these steps:
-
Open Web.config file located in
src\api\Main\PresentationLayer\Shrooms.Presentation.Api\
-
Locate
<resizer>
block and uncomment lines inside of<plugins>
block as shown bellow<resizer> <plugins> <add name="AzureReader2" prefix="~/storage" connectionString="yourBlobStorageConnectionString" endpoint="https://your-project.blob.core.windows.net/" /> <add name="AnimatedGifs" /> <add name="DiskCache" /> <add name="PrettyGifs" /> </plugins> </resizer>
To use AzureReader2 plugin you will have to provder your connectionString
and endpoint
, paste these values to appropriate places inside add
block with name="AzureReader2"
attribute. If you have a Redirect to Azure Blob Storage
rule enabled don't forget to disable it.
To use these plugins in production environment you will have to put ImageResizer license inside <license>
block as shown below
<resizer>
<licenses>
<license>
<!-- ImageResizer license here -->
</license>
</licenses>
</resizer>
- Open model (e.g.
ServiceRequest.cs
) and add new property, for example:
public string PictureId { get; set; }
- Open Package Manager Console in Visual Studio and call command:
add-migration MigrationName -ConnectionString "ConnectionString" -ConnectionProviderName "System.Data.SqlClient" -StartUpProjectName Shrooms.Presentation.Api -ProjectName Shrooms.DataLayer
Connection string can be found in Web.config
.
- Once it was done - new migration file should appear in
DataLayer
project. Content should be something like:
AddColumn("dbo.ServiceRequests", "PictureId", c => c.String());
- To apply migration on the database, execute following command in Package Manager Console:
update-database -verbose -ConnectionString "ConnectionString" -ConnectionProviderName "System.Data.SqlClient" -StartUpProjectName Shrooms.Presentation.Api -ProjectName Shrooms.DataLayer
4.1 To rollback to previous migration, execute following command:
update-database -verbose -ConnectionString "ConnectionString" -ConnectionProviderName "System.Data.SqlClient" -StartUpProjectName Shrooms.Presentation.Api -ProjectName Shrooms.DataLayer –TargetMigration "202001021211276_MigrationName"
- Migration is done
For more details, please reffer to https://msdn.microsoft.com/en-us/library/jj591621(v=vs.113).aspx or http://www.entityframeworktutorial.net/code-first/code-based-migration-in-code-first.aspx