public ActionResult Create([Bind(Include = "Id,Title,AUrl,Status")] Attachment attachment) { if (ModelState.IsValid) { db.Attachments.Add(attachment); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(attachment)); }
public OperationResult Delete(int id) { OperationResult operationResult = new OperationResult(); try { Attachment attachment = GetAttachment(id); if (attachment != null) { AttachmentContext db = new AttachmentContext(); db.Entry(attachment).State = EntityState.Deleted; db.SaveChanges(); operationResult.Success = true; operationResult.Message = "Attachment Deleted Successfully"; } else { operationResult.Success = false; operationResult.Message = "Attachment not found"; } } catch (Exception ex) { operationResult.Success = false; operationResult.Message = "An Error Ocured During Deleting the Attachment"; } return(operationResult); }
public int SaveAttachment(Attachment attachmentToCreate) { _attachmentContext.Add(attachmentToCreate); int response = _attachmentContext.SaveChanges(); return(response); }
public OperationResult SaveAttachments(List <Attachment> NewAttachments) { OperationResult operationResult = new OperationResult(); try { AttachmentContext db = new AttachmentContext(); db.Attachments.AddRange(NewAttachments); db.SaveChanges(); operationResult.Success = true; operationResult.Message = "Attachments Added Successfully"; } catch (Exception ex) { operationResult.Success = false; operationResult.Message = "An Error Ocured During saving the new Attachments "; } return(operationResult); }