public DataReturn SaveAttachmentInJobFile(JobFileClass model) { DataReturn obj = new DataReturn(); try { JobFile fj = db.JobFile.SingleOrDefault(m => m.JobKey == model.JobKey && m.DocumentTypeKey == model.DocumentTypeKey); if (fj == null) { } else { db.JobFile.Remove(fj); db.SaveChanges(); db = new RCSdbEntities(); } JobFile invoice = new JobFile(); Job job = db.Job.Find(model.JobKey); invoice.FileKey = Guid.NewGuid(); invoice.JobKey = (Guid)model.JobKey; invoice.DocumentTypeKey = model.DocumentTypeKey; //invoice.AddedBy = GlobalClass.LoginUser.PersonnelKey; invoice.AddedOn = System.DateTime.Now; if (string.IsNullOrEmpty(model.Comment)) { invoice.Comment = "--"; } else { invoice.Comment = model.Comment; } invoice.Title = model.Title; invoice.Remarks = db.DocumentType.Find(model.DocumentTypeKey).TName + " is Added by " + GlobalClass.LoginUser.Cname; invoice.FileContent = model.FileContent; invoice.FileType = model.FileType; invoice.IsDelete = false; invoice.IsFileNew = true; db.JobFile.Add(invoice); db.SaveChanges(); obj.flag = 1; obj.mess = "Data has been updated successfully."; } catch (Exception ex) { obj.mess = ex.ToString(); obj.flag = 0; } obj.key = model.JobKey; return(obj); }
public ActionResult Delete(Guid id) { if (GlobalClass.SystemSession) { var Jobrq = db.JobRequestAttachments.Where(f => f.RequestKey == id).ToList(); db.JobRequestAttachments.RemoveRange(Jobrq); db.SaveChanges(); db = new RCSdbEntities(); JobRequest obj = db.JobRequest.Find(id); db.JobRequest.Remove(obj); db.SaveChanges(); return(RedirectToAction("Index")); } else { Exception e = new Exception("Sorry, your Session has Expired"); return(View("Error", new HandleErrorInfo(e, "Home", "Logout"))); } }
public DataReturn SaveAttachmentInRequest(JobRequestAttachmentMain model) { DataReturn obj = new DataReturn(); try { JobRequestAttachments fj = db.JobRequestAttachments.SingleOrDefault(m => m.RequestKey == model.RequestObj.RequestKey && m.DocumentTypeKey == model.DocumentTypeKey); if (fj == null) { } else { db.JobRequestAttachments.Remove(fj); db.SaveChanges(); db = new RCSdbEntities(); } JobRequestAttachments invoice = new JobRequestAttachments(); invoice.PKey = Guid.NewGuid(); invoice.RequestKey = (Guid)model.RequestObj.RequestKey; invoice.DocumentTypeKey = model.DocumentTypeKey; invoice.DocFile = model.fileObj.DocFile; invoice.Filename = model.fileObj.Filename; invoice.FileType = model.fileObj.FileType; db.JobRequestAttachments.Add(invoice); db.SaveChanges(); obj.flag = 1; obj.mess = "Data has been updated successfully."; } catch (Exception ex) { obj.mess = ex.ToString(); obj.flag = 0; } obj.key = model.RequestObj.RequestKey; return(obj); }