public bool CreateAttachment(AttachmentCreate model) { var entity = new Attachment() { OwnerId = _userId, Name = model.Name, Description = model.Description, IsPrimary = model.IsPrimary, CreatedUtc = DateTimeOffset.Now }; using (var ctx = new ApplicationDbContext()) { ctx.Attachments.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(AttachmentCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateAttachmentService(); if (service.CreateAttachment(model)) { ViewBag.SaveResult = "Your nattachment was created"; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Note could not be created."); return(View(model)); }