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));
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public int SaveAttachment(Attachment attachmentToCreate)
        {
            _attachmentContext.Add(attachmentToCreate);
            int response = _attachmentContext.SaveChanges();

            return(response);
        }
Exemplo n.º 4
0
        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);
        }