poprawiony kontroler MailSender

This commit is contained in:
s440054 2018-12-19 13:09:24 +01:00
parent c79fed0334
commit 851b633e31
3 changed files with 10 additions and 8 deletions

View File

@ -9,7 +9,6 @@ namespace MailDTO
public class MailDTO
{
public string Subject { get; set; }
public string EMailTo { get; set; }
public string Content { get; set; }
}

View File

@ -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);
}

View File

@ -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;
}
}
}