poprawiony kontroler MailSender
This commit is contained in:
parent
c79fed0334
commit
851b633e31
@ -9,7 +9,6 @@ namespace MailDTO
|
||||
public class MailDTO
|
||||
{
|
||||
public string Subject { get; set; }
|
||||
|
||||
public string EMailTo { get; set; }
|
||||
public string Content { get; set; }
|
||||
}
|
||||
|
@ -12,12 +12,7 @@ namespace MailSender.Controllers
|
||||
[HttpPost]
|
||||
public ActionResult Index([System.Web.Http.FromBody]MailDTO.MailDTO mail)
|
||||
{
|
||||
string jsonString = TempData["mailModel"] as string;
|
||||
Models.MailModel model = null;
|
||||
if (!String.IsNullOrEmpty(jsonString))
|
||||
model = JsonConvert.DeserializeObject<Models.MailModel>(jsonString);
|
||||
if (model == null)
|
||||
model = new Models.MailModel();
|
||||
var model = new Models.MailModel(mail);
|
||||
return View(model);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using MailDTO;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace MailSender.Models
|
||||
@ -17,7 +18,7 @@ namespace MailSender.Models
|
||||
public string Subject { get; set; }
|
||||
|
||||
[DataType(DataType.EmailAddress)]
|
||||
[Required(AllowEmptyStrings = false, ErrorMessage = "Musisz wprowadzić adres e-mail")]
|
||||
[Required(AllowEmptyStrings = false, ErrorMessage = "Musisz wprowadzić adres e-mail odbiorcy")]
|
||||
[RegularExpression(".*@.*\\..*", ErrorMessage = "Zły format")]
|
||||
[Display(Name = "Adres odbiorcy")]
|
||||
[EmailAddress(ErrorMessage ="Zły format")]
|
||||
@ -29,5 +30,12 @@ namespace MailSender.Models
|
||||
[StringLength(500, ErrorMessage = "Message has to have between 1 and 500 chars", MinimumLength = 1)]
|
||||
public string Content { get; set; }
|
||||
|
||||
|
||||
public MailModel(MailDTO.MailDTO DTO)
|
||||
{
|
||||
this.Content = DTO.Content;
|
||||
this.EMailTo = DTO.EMailTo;
|
||||
this.Subject = DTO.Subject;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user