public bool UpdateDocument(DocumentVM documentVM) { using (var dbTransaction = unitOfWork.dbContext.Database.BeginTransaction()) { try { tblDocument document = unitOfWork.TblDocumentRepository.GetByID(documentVM.DocumentID); document.InsSubClassID = documentVM.InsuranceSubClassID; document.DocumentPath = documentVM.DocumentPath; document.Description = documentVM.Description; document.ModifiedDate = DateTime.Now; document.ModifiedBy = documentVM.ModifiedBy; unitOfWork.TblDocumentRepository.Update(document); unitOfWork.Save(); //Complete the Transaction dbTransaction.Commit(); return(true); } catch (Exception ex) { //Roll back the Transaction dbTransaction.Rollback(); return(false); } } }
public int UpdateDocument(DocumentModel model) { if (model.FromScreen == "companyScreen") { model.IsCompanyAccessOnly = true; } else { model.IsCompanyAccessOnly = false; } var document = _documentRepository.Find(x => x.DocumentID == model.DocumentID).FirstOrDefault(); if (document != null) { model.LastUpdatedDate = DateTime.Now; Mapper.CreateMap <DocumentModel, tblDocument>() .ForMember(dest => dest.DocumentID, opt => opt.Ignore()); // ignore primary key while update/delete tblDocument documentEnity = (tblDocument)Mapper.Map(model, document); return(_documentRepository.SaveChanges()); } return(0); }
// GET: /Users/ public ActionResult Index(int isdelete = 0, int restoreid = 0) { var list = (dynamic)null; TempData["restore"] = ""; if (isdelete == 0) { if (restoreid > 0) { if (db.tblDocument.Any(a => a.DocumentID == restoreid && a.IsDelete == true)) { tblDocument tblDocument = db.tblDocument.Find(restoreid); tblDocument.IsDelete = false; db.Entry(tblDocument).State = EntityState.Modified; db.SaveChanges(); TempData["msg"] = "Record Restore Successfully"; // return View("Index","Document"); } } list = db.tblDocument.Where(a => a.IsDelete != true).OrderByDescending(a => a.DocumentID).ToList(); } else { TempData["restore"] = "restore"; list = db.tblDocument.Where(a => a.IsDelete == true).OrderByDescending(a => a.DocumentID).ToList(); } return(View(list)); }
public ActionResult DeleteConfirmed(int id) { tblDocument tblDocument = db.tblDocument.Find(id); db.tblDocument.Remove(tblDocument); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "DocumentID,DocumentName,Password,CreatedBy,UpdatedBy,CreateDate,UpdateDate,IsLogin,IsDelete,IsActive,RoleID,SchoolID,DeleteBy,DeleteDate")] tblDocument tblDocument) { if (ModelState.IsValid) { db.tblDocument.Add(tblDocument); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tblDocument)); }
public tblDocument CreatePRItems(ProcureVM model) { var user = System.Web.HttpContext.Current.Session["UserName"].ToString(); var add = new tblDocument() { CreationDate = DateTime.Now, CreatedBy = user, }; return(add); }
public ActionResult Edit([Bind(Include = "DocumentID,DocumentName,Password,CreatedBy,UpdatedBy,CreateDate,UpdateDate,IsLogin,IsDelete,IsActive,RoleID,SchoolID,DeleteBy,DeleteDate")] tblDocument tblDocument) { if (ModelState.IsValid) { db.Entry(tblDocument).State = EntityState.Modified; db.SaveChanges(); TempData["msg"] = "Record Update Successfully"; return(RedirectToAction("Index")); } return(View(tblDocument)); }
// GET: /Users/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tblDocument tblDocument = db.tblDocument.Find(id); if (tblDocument == null) { return(HttpNotFound()); } return(View(tblDocument)); }
public tblDocument Addpr(DateTime reqdate) { var user = System.Web.HttpContext.Current.Session["UserName"].ToString(); var add = new tblDocument() { DTypeId = 1, CreationDate = DateTime.Now, CreatedBy = user, DocStatus = "Complete", Status = "Pending", ItemRequestedDate = reqdate, }; return(add); }
public tblDocument AddGI() { var user = System.Web.HttpContext.Current.Session["UserName"].ToString(); var add = new tblDocument() { DTypeId = 6, CreationDate = DateTime.Now.Date, CreatedBy = user, DocStatus = "Complete", Status = "Complete", IssuedDate = DateTime.Now.Date, }; return(add); }
// GET: /Users/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tblDocument tblDocument = db.tblDocument.Find(id); ViewBag.RoleID = new SelectList(db.tblRoles, "RoleID", "RoleName", tblDocument.DocumentID); ViewBag.SchoolID = new SelectList(db.tblSchool, "SchoolID", "SchoolName", tblDocument.SchoolID); if (tblDocument == null) { return(HttpNotFound()); } return(View(tblDocument)); }
public tblDocument AddGrwithcompReturn(int returnrefno, int vendor) { var user = System.Web.HttpContext.Current.Session["UserName"].ToString(); var add = new tblDocument() { DTypeId = 4, CreationDate = DateTime.Now.Date, CreatedBy = user, DocStatus = "Complete", Status = "Complete", VendorId = vendor, ReturnReferenceno = returnrefno, }; return(add); }
public tblDocument AddPowithref(int PRref, int vendorid, DateTime reqdate, DateTime deldate) { var user = System.Web.HttpContext.Current.Session["UserName"].ToString(); var add = new tblDocument() { DTypeId = 3, CreationDate = DateTime.Now.Date, CreatedBy = user, DocStatus = "Complete", PrReferenceNo = PRref, VendorId = vendorid, ItemRequestedDate = reqdate, DeliveryDate = deldate, }; return(add); }
public tblDocument Addrd(int vendorid, int grref, string reasonofreturn, DateTime dateofdev, int prref) { var user = System.Web.HttpContext.Current.Session["UserName"].ToString(); var add = new tblDocument() { DTypeId = 5, CreationDate = DateTime.Now.Date, CreatedBy = user, DocStatus = "Complete", Status = "InProgress", VendorId = vendorid, GRReferencenoforReturn = grref, Reasonofreturn = reasonofreturn, DeliveryDate = dateofdev, PrReferenceNo = prref, }; return(add); }
public HttpResponseMessage SaveFile() { try { //Create HTTP Response. HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK); //Check if Request contains File. if (HttpContext.Current.Request.Files.Count == 0) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } //Read the File data from Request.Form collection. HttpPostedFile postedFile = HttpContext.Current.Request.Files[0]; //Convert the File data to Byte Array. byte[] bytes; using (BinaryReader br = new BinaryReader(postedFile.InputStream)) { bytes = br.ReadBytes(postedFile.ContentLength); } //Insert the File to Database Table. FilesEntities entities = new FilesEntities(); tblDocument file = new tblDocument { Name = Path.GetFileName(postedFile.FileName), ContentType = postedFile.ContentType, Data = bytes, UserId = 1016879 }; entities.tblDocuments.Add(file); entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, new { id = file.id, Name = file.Name })); } catch (Exception) { return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } }
public bool DeleteDocument(int documentID) { using (var dbTransaction = unitOfWork.dbContext.Database.BeginTransaction()) { try { tblDocument document = unitOfWork.TblDocumentRepository.GetByID(documentID); unitOfWork.TblDocumentRepository.Delete(document); unitOfWork.Save(); //Complete the Transaction dbTransaction.Commit(); return(true); } catch (Exception ex) { //Roll back the Transaction dbTransaction.Rollback(); return(false); } } }
public ActionResult CreateDocument(DocumentModel vm) { tblDocument doc = new tblDocument(); if (vm.IsEdit) { doc = _context.tblDocuments.SingleOrDefault(x => x.Id == vm.Id); } doc.Name = vm.Name; doc.SubCategoryId = vm.SubCategoryId; doc.CategoryId = vm.CategoryId; doc.Descriptions = vm.Descriptions; doc.DocumentPath = vm.DocumentPath; if (!vm.IsEdit) { _context.tblDocuments.Add(doc); } _context.SaveChanges(); var exstingkeyword = _context.tblDocumentKeyWordMaps.Where(x => x.DocumentId == doc.Id); if (exstingkeyword.Count() != 0) { _context.tblDocumentKeyWordMaps.RemoveRange(exstingkeyword); } vm.Keywords.ToList().ForEach(x => _context.tblDocumentKeyWordMaps.Add(new tblDocumentKeyWordMap() { DocumentId = doc.Id, KeyWordId = x })); _context.SaveChanges(); return(RedirectToAction("Index", new { area = "Document" })); }
public HttpResponseMessage GetFile(int fileId) { //Create HTTP Response. HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK); //Fetch the File data from Database. FilesEntities entities = new FilesEntities(); tblDocument file = entities.tblDocuments.ToList().Find(p => p.id == fileId); //Set the Response Content. response.Content = new ByteArrayContent(file.Data); //Set the Response Content Length. response.Content.Headers.ContentLength = file.Data.LongLength; //Set the Content Disposition Header Value and FileName. response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); response.Content.Headers.ContentDisposition.FileName = file.Name; //Set the File Content Type. response.Content.Headers.ContentType = new MediaTypeHeaderValue(file.ContentType); return(response); }
public void addgr(tblDocument obj) { context.tblDocuments.Add(obj); }
public ActionResult Create(FormViewModel Model) { FormsDataContext FormsDB = new FormsDataContext(); tblForm ExistingForm = FormsDB.tblForms.Where(e => e.ID == Model.ID).SingleOrDefault(); if (ExistingForm != null) { Model.ReloadExistingDocuments(ExistingForm); } if (ModelState.IsValid) { if (CustomRequestValidation(Model)) { tblForm Form = null; // Create form DB object from Model try { Form = new tblForm(Model); } catch (Exception ex) { TempData[ORSPARouting.Models.DataConstants.ErrorKey] = "An error occurred when attempting to save the form. The values were not saved. The error has been logged."; TempData[ORSPARouting.Models.DataConstants.ReattachDocumentsNoticeKey] = ORSPARouting.Models.DataConstants.ReattachDocumentsNotice; SecureAccess.Utilities.Logging.LogException(Logging.LogType.Audit, "RequestController -> Create() : An error occurred when attempting to build a tblForm object from a Model.", ex); Model.Project = FormsDB.tblProjects.Where(e => e.ID == Model.ProjectID).FirstOrDefault(); return(View("New", Model)); } // Save form to DB Form.SubmitterUsername = Current.User.Username; Form.Submitter = Current.User.ENumber; Form.IsSubmitted = false; // only mark submitted when everything goes ok Form.SubmittedDate = DateTime.Now; FormsDB.tblForms.InsertOnSubmit(Form); FormsDB.SubmitChanges(); #region Handle Existing Form (either submitting a rejected or unsubmitted form) if (ExistingForm != null) { // set Workflow from old form Form.WorkflowInstanceID = ExistingForm.WorkflowInstanceID; // set Documents from old form foreach (tblDocument Doc in ExistingForm.tblDocuments.ToList()) { Doc.tblForm = Form; } // delete old form data FormsDB.tblFields.DeleteAllOnSubmit(ExistingForm.tblSections.SelectMany(e => e.tblFields)); FormsDB.tblSections.DeleteAllOnSubmit(ExistingForm.tblSections); FormsDB.tblForms.DeleteOnSubmit(ExistingForm); } #endregion // save changes before new document attachment FormsDB.SubmitChanges(); #region Save Documents... // save uploaded files if (Model.Documents != null && Model.Documents.Files != null) { List <tblDocument> DocumentsToSave = new List <tblDocument>(); foreach (FileBundle bundle in Model.Documents.Files) { if (bundle.File != null && bundle.File.ContentLength > 0) { // Save as unique path name Form##_Filename. ex.(Form13_ConflictofInterest.doc) var fileName = String.Format("Form{0}_{1}", Form.ID, Path.GetFileName(bundle.File.FileName)); var path = Path.Combine(Server.MapPath("~/uploads"), fileName); bundle.File.SaveAs(path); tblDocument document = new tblDocument(); document.FormID = Form.ID; document.FriendlyFilename = Path.GetFileName(bundle.File.FileName); document.ActualFilename = fileName; document.Description = bundle.Description; document.Type = bundle.Type; DocumentsToSave.Add(document); } } if (DocumentsToSave.Count > 0) { FormsDB.tblDocuments.InsertAllOnSubmit(DocumentsToSave); FormsDB.SubmitChanges(); } } #endregion #region Handle Workflow // We're submitting request. If there was no existing form to get a workflow from or there was an existing form, but there is no WorkflowInstanceID, or the workflow exists and was rejected, create a workflow if (ExistingForm == null || (ExistingForm != null && !Form.WorkflowInstanceID.HasValue) || (ExistingForm != null && Form.WorkflowInstanceID.HasValue && Workflows.GetWorkflow(Form.WorkflowInstanceID.Value).Rejected)) { try { #region Create Workflow... // Create Workflow, save instance id to Form tblProject Project = FormsDB.tblProjects.Where(e => e.ID == Model.ProjectID).SingleOrDefault(); List <WorkflowPersonnel> KeyPersonnel = Project.tblProjectPersonnels.Where(e => e.IsPrincipalInvestigator == false).Select(e => new WorkflowPersonnel() { ENumber = Banner.GetUser(e.Username).ENumber, OrganizationCode = e.DepartmentCollege }).ToList <WorkflowPersonnel>(); tblProjectPersonnel PIData = Project.tblProjectPersonnels.Where(e => e.IsPrincipalInvestigator).SingleOrDefault(); WorkflowPersonnel PI = new WorkflowPersonnel() { ENumber = Banner.GetUser(PIData.Username).ENumber, OrganizationCode = PIData.DepartmentCollege }; Form.WorkflowInstanceID = Workflows.CreateWorkflow(PI, KeyPersonnel); FormsDB.SubmitChanges(); #endregion } catch (Exception ex) { // on workflow create exception, set form as unsubmitted so it won't get stuck in limbo or lost. Form.IsSubmitted = false; FormsDB.SubmitChanges(); throw ex; } } #endregion // everything went ok, so mark form as submitted. Form.IsSubmitted = true; FormsDB.SubmitChanges(); SecureAccess.Utilities.Logging.Log(Logging.LogType.Audit, string.Format("User {0} successfully submitted a request. FormID: {1}; FormType: {2}", Current.User.Username, Form.ID, Form.FormType)); } else { TempData[ORSPARouting.Models.DataConstants.ReattachDocumentsNoticeKey] = ORSPARouting.Models.DataConstants.ReattachDocumentsNotice; Model.Project = (new FormsDataContext()).tblProjects.Where(e => e.ID == Model.ProjectID).FirstOrDefault(); return(View("New", Model)); } } else { TempData[ORSPARouting.Models.DataConstants.ErrorKey] = ORSPARouting.Models.DataConstants.ModelStateInvalidError; TempData[ORSPARouting.Models.DataConstants.ReattachDocumentsNoticeKey] = ORSPARouting.Models.DataConstants.ReattachDocumentsNotice; Model.Project = (new FormsDataContext()).tblProjects.Where(e => e.ID == Model.ProjectID).FirstOrDefault(); return(View("New", Model)); } return(RedirectToAction("Status", "Projects")); }
public ActionResult Save(FormViewModel Model) { // builds new form data model from submitted form, keeps documents and workflow from old tblForm, and throws away the old values. FormsDataContext FormsDB = new FormsDataContext(); tblForm ExistingForm = FormsDB.tblForms.Where(e => e.ID == Model.ID).SingleOrDefault(); if (ExistingForm != null) { Model.ReloadExistingDocuments(ExistingForm); } if (ModelState.IsValid) { if (CustomRequestValidation(Model)) { tblForm Form = null; // Create form DB object from Model try { Form = new tblForm(Model); } catch (Exception ex) { TempData[ORSPARouting.Models.DataConstants.ErrorKey] = "An error occurred when attempting to save the form. The values were not saved. The error has been logged."; TempData[ORSPARouting.Models.DataConstants.ReattachDocumentsNoticeKey] = ORSPARouting.Models.DataConstants.ReattachDocumentsNotice; SecureAccess.Utilities.Logging.LogException(Logging.LogType.Audit, "RequestController -> Save() : An error occurred when attempting to build a tblForm object from a Model.", ex); Model.Project = FormsDB.tblProjects.Where(e => e.ID == Model.ProjectID).FirstOrDefault(); return(View("Edit", Model)); } // Save form data to DB Form.SubmitterUsername = Current.User.Username; Form.Submitter = Current.User.ENumber; Form.IsSubmitted = false; FormsDB.tblForms.InsertOnSubmit(Form); FormsDB.SubmitChanges(); if (ExistingForm != null) { // set Workflow from old form Form.WorkflowInstanceID = ExistingForm.WorkflowInstanceID; Form.IsSubmitted = ExistingForm.IsSubmitted; Form.SubmittedDate = ExistingForm.SubmittedDate; // set Documents from old form foreach (tblDocument Doc in ExistingForm.tblDocuments.ToList()) { Doc.tblForm = Form; } // delete old form data FormsDB.tblFields.DeleteAllOnSubmit(ExistingForm.tblSections.SelectMany(e => e.tblFields)); FormsDB.tblSections.DeleteAllOnSubmit(ExistingForm.tblSections); FormsDB.tblForms.DeleteOnSubmit(ExistingForm); } // save changes before new document attachment FormsDB.SubmitChanges(); #region Save Documents from input... if (Model.Documents != null && Model.Documents.Files != null) { // save uploaded files List <tblDocument> DocumentsToSave = new List <tblDocument>(); foreach (FileBundle bundle in Model.Documents.Files) { if (bundle.File != null && bundle.File.ContentLength > 0) { // Save as unique path name Form##_Filename. ex.(Form13_ConflictofInterest.doc) var fileName = String.Format("Attachment_{0}_{1}", Path.GetFileName(bundle.File.FileName), DateTime.Now.ToString("yyyyMMddHmmss")); var path = Path.Combine(Server.MapPath("~/uploads"), fileName); bundle.File.SaveAs(path); tblDocument document = new tblDocument(); document.FormID = Form.ID; document.FriendlyFilename = Path.GetFileName(bundle.File.FileName); document.ActualFilename = fileName; document.Description = bundle.Description; document.Type = bundle.Type; DocumentsToSave.Add(document); } } if (DocumentsToSave.Count > 0) { FormsDB.tblDocuments.InsertAllOnSubmit(DocumentsToSave); FormsDB.SubmitChanges(); } } #endregion // Don't Create Workflow // log SecureAccess.Utilities.Logging.Log(Logging.LogType.Audit, string.Format("User {0} successfully saved a request. FormID: {1}; FormType: {2}", Current.User.Username, Form.ID, Form.FormType)); this.ShowPageMessage(String.Format("Request successfully saved: {0}", DateTime.Now.ToLongTimeString())); return(RedirectToAction("Edit", new { @ID = Form.ID })); } // end custom validation IF block else { TempData[ORSPARouting.Models.DataConstants.ReattachDocumentsNoticeKey] = ORSPARouting.Models.DataConstants.ReattachDocumentsNotice; Model.Project = (new FormsDataContext()).tblProjects.Where(e => e.ID == Model.ProjectID).FirstOrDefault(); return(View("Edit", Model)); } } else { TempData[ORSPARouting.Models.DataConstants.ErrorKey] = ORSPARouting.Models.DataConstants.ModelStateInvalidError; TempData[ORSPARouting.Models.DataConstants.ReattachDocumentsNoticeKey] = ORSPARouting.Models.DataConstants.ReattachDocumentsNotice; Model.Project = FormsDB.tblProjects.Where(e => e.ID == Model.ProjectID).FirstOrDefault(); return(View("Edit", Model)); } // all paths above should return a value }
public void AddPRItems(tblDocument obj) { context.tblDocuments.Add(obj); }