Skip to content

Commit

Permalink
- Adding new common validator
Browse files Browse the repository at this point in the history
  • Loading branch information
MandarTisge committed Nov 20, 2014
1 parent 8bdc55e commit 958fb4c
Show file tree
Hide file tree
Showing 12 changed files with 279 additions and 20 deletions.
48 changes: 48 additions & 0 deletions FSDTS/Common/CustomValidators.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using FSDTS.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace FSDTS.Common
{
public class CustomValidators
{
public class ValidateDateAttribute : ValidationAttribute
{
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
Period period = new Period();
period = (Period)validationContext.ObjectInstance;

if (!(period.PeriodEndDate >= (DateTime)value)) // || !(period.PeriodDeadlineDate >= (DateTime)value)
{
return new ValidationResult(ErrorMessage);
}
else
{
return ValidationResult.Success;
}
}
}

public class ValidateYearAttribute : ValidateDateAttribute
{
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
Project project = new Project();
project = (Project)validationContext.ObjectInstance;

if (!(Convert.ToInt32(project.ProjectEndYear)> Convert.ToInt32(value)))
{
return new ValidationResult(ErrorMessage);
}
else
{
return ValidationResult.Success;
}
}
}
}
}
24 changes: 24 additions & 0 deletions FSDTS/Common/FsdtsCommonMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Mail;
using System.Web;
using System.Web.Http;

Expand Down Expand Up @@ -57,5 +58,28 @@ public static void NullValueHandler(string itemType)
}
throw new HttpResponseException(httpResponseMessage);
}


public static bool SendEmail(string toEmailId, string subject, string body)
{
// FsdtsCommonMethods.SendEmail("sender's email id", "testsubject", "testbody");
NetworkCredential NetworkCredentials = new System.Net.NetworkCredential(FsdtsConstants.SenderEmailId, FsdtsConstants.SenderPassword);

SmtpClient smtpClient = new SmtpClient
{
Host = FsdtsConstants.SMTPHost,
Port = FsdtsConstants.SMTPPort,
EnableSsl = true,
DeliveryMethod = FsdtsConstants.SMTPDeliveryMethod,
Credentials = NetworkCredentials,
Timeout = 30000,
};

MailMessage message = new MailMessage(FsdtsConstants.SenderEmailId, toEmailId, subject, body);

smtpClient.Send(message);

return true;
}
}
}
15 changes: 15 additions & 0 deletions FSDTS/Common/FsdtsConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace FSDTS.Common
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Web;

/// <summary>
Expand Down Expand Up @@ -61,6 +62,20 @@ public class FsdtsConstants
/// </summary>
public const string ItemNotFound = "Item you are searching not found.";

#region Fields used for Notification (Email) functionality

public const string SenderEmailId = "[email protected]";

public const string SenderPassword = "Mobile1234";

public const string SMTPHost = "smtp.gmail.com";

public const int SMTPPort = 587;

public const System.Net.Mail.SmtpDeliveryMethod SMTPDeliveryMethod = "SmtpDeliveryMethod.Network";

#endregion

#region Generic fields used across all the controllers
/// <summary>
/// For Get() method (Ex. GetCourse(), GetProgram() etc.)
Expand Down
20 changes: 6 additions & 14 deletions FSDTS/FSDTS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Antlr3.Runtime">
<Reference Include="Antlr3.Runtime, Version=3.5.0.2, Culture=neutral, PublicKeyToken=eb42632606e9261f, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Antlr3.Runtime.3.5.0.3-alpha002\lib\net20\Antlr3.Runtime.dll</HintPath>
<HintPath>..\packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll</HintPath>
</Reference>
<Reference Include="EntityFramework">
<HintPath>..\packages\EntityFramework.6.1.1\lib\net45\EntityFramework.dll</HintPath>
Expand All @@ -65,14 +65,6 @@
<HintPath>..\packages\Microsoft.AspNet.Identity.Owin.1.0.0\lib\net45\Microsoft.AspNet.Identity.Owin.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.Data.Edm, Version=5.6.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Microsoft.Data.Edm.5.6.3\lib\net40\Microsoft.Data.Edm.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Data.OData, Version=5.6.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Microsoft.Data.OData.5.6.3\lib\net40\Microsoft.Data.OData.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Owin">
<HintPath>..\packages\Microsoft.Owin.3.0.0\lib\net45\Microsoft.Owin.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -123,10 +115,6 @@
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.2\lib\net45\System.Net.Http.Formatting.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Spatial, Version=5.6.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\System.Spatial.5.6.3\lib\net40\System.Spatial.dll</HintPath>
</Reference>
<Reference Include="System.Web.Cors">
<HintPath>..\packages\Microsoft.AspNet.Cors.5.2.2\lib\net45\System.Web.Cors.dll</HintPath>
</Reference>
Expand All @@ -146,6 +134,9 @@
<Reference Include="System.Web.Http.Cors">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Cors.5.2.2\lib\net45\System.Web.Http.Cors.dll</HintPath>
</Reference>
<Reference Include="System.Web.Http.OData">
<HintPath>..\packages\Microsoft.AspNet.WebApi.OData.5.3.1\lib\net45\System.Web.Http.OData.dll</HintPath>
</Reference>
<Reference Include="System.Web.Http.Owin">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Owin.5.2.2\lib\net45\System.Web.Http.Owin.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -231,6 +222,7 @@
<Compile Include="Areas\HelpPage\SampleGeneration\SampleDirection.cs" />
<Compile Include="Areas\HelpPage\SampleGeneration\TextSample.cs" />
<Compile Include="Areas\HelpPage\XmlDocumentationProvider.cs" />
<Compile Include="Common\CustomValidators.cs" />
<Compile Include="Common\FsdtsCommonMethods.cs" />
<Compile Include="Common\FsdtsConstants.cs" />
<Compile Include="Common\FsdtsExceptionHandlerAttribute.cs" />
Expand Down
29 changes: 29 additions & 0 deletions FSDTS/Migrations/201411181324112_initiald.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions FSDTS/Migrations/201411181324112_initiald.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace FSDTS.Migrations
{
using System;
using System.Data.Entity.Migrations;

public partial class initiald : DbMigration
{
public override void Up()
{
AddColumn("dbo.Users", "UserPassword", c => c.String());
}

public override void Down()
{
DropColumn("dbo.Users", "UserPassword");
}
}
}
Loading

0 comments on commit 958fb4c

Please sign in to comment.