public int UpdateOutward(tblOutwardWO outWardData) { try { using (var dbContext = new PMSEntities()) { dbContext.tblOutwardWOes.Attach(outWardData); dbContext.Entry(outWardData).State = EntityState.Modified; dbContext.SaveChanges(); } return(1); } catch (Exception ex) { return(0); } }
public int SaveOutward(tblOutwardWO outWardData) { try { using (var dbContext = new PMSEntities()) { outWardData.WOId = Guid.NewGuid(); dbContext.tblOutwardWOes.Add(outWardData); dbContext.SaveChanges(); } return(1); } catch (Exception ex) { return(0); } }
public int UpdateOutward(tblOutwardWO outWardData) { return(_workOrderRepository.UpdateOutward(outWardData)); }
public JsonResult SaveOutwardData() { int result = 0; try { tblOutwardWO data = JsonConvert.DeserializeObject <tblOutwardWO>(Request["outwardData"]); if (Request.Files.Count > 0) { string folderPath = ConfigurationManager.AppSettings["OutwardsPath"]; string selectedFileName = Request.Files[0].FileName.Split(';')[0]; HttpFileCollectionBase files = Request.Files; HttpPostedFileBase file = files[0]; string fileName = ""; if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } if (data.IsWorkOrderFileAttached) { fileName = Request.Files[0].FileName; if (!string.IsNullOrEmpty(data.WOFilePath) && data.IsWorkOrderFileAttached) { System.IO.File.Delete(data.WOFilePath); } if (!System.IO.File.Exists(folderPath + fileName)) { Request.Files[0].SaveAs(folderPath + fileName); data.WOFilePath = folderPath + fileName; data.WOFileName = fileName; } else { fileName = "1_" + Request.Files[0].FileName; if (!System.IO.File.Exists(folderPath + fileName)) { fileName = DateTime.Now.ToString("ddMMyyyHHmmsss") + "_1_" + Request.Files[0].FileName; } Request.Files[0].SaveAs(folderPath + fileName); data.WOFilePath = folderPath + fileName; data.WOFileName = fileName; } } if (data.IsVendor1FileAttached) { int index = 1; if (!data.IsWorkOrderFileAttached) { index = 0; } fileName = Request.Files[index].FileName; if (!string.IsNullOrEmpty(data.VendorFilePath1) && data.IsVendor1FileAttached) { System.IO.File.Delete(data.VendorFilePath1); } if (!System.IO.File.Exists(folderPath + fileName)) { Request.Files[index].SaveAs(folderPath + fileName); data.VendorFilePath1 = folderPath + fileName; data.VendorFileName1 = fileName; } else { fileName = "1_" + Request.Files[index].FileName; if (!System.IO.File.Exists(folderPath + fileName)) { fileName = DateTime.Now.ToString("ddMMyyyHHmmsss") + "_1_" + Request.Files[index].FileName; } Request.Files[index].SaveAs(folderPath + fileName); data.VendorFilePath1 = folderPath + fileName; data.VendorFileName1 = fileName; } } if (data.IsVendor2FileAttached) { int index = 2; if (!data.IsVendor1FileAttached) { index = index - 1; } if (!data.IsWorkOrderFileAttached) { index = index - 1; } fileName = Request.Files[index].FileName; if (!string.IsNullOrEmpty(data.VendorFilePath2) && data.IsVendor2FileAttached) { System.IO.File.Delete(data.VendorFilePath2); } if (!System.IO.File.Exists(folderPath + fileName)) { Request.Files[index].SaveAs(folderPath + fileName); data.VendorFilePath2 = folderPath + fileName; data.VendorFileName2 = fileName; } else { fileName = "1_" + Request.Files[index].FileName; if (!System.IO.File.Exists(folderPath + fileName)) { fileName = DateTime.Now.ToString("ddMMyyyHHmmsss") + "_2_" + Request.Files[index].FileName; } Request.Files[index].SaveAs(folderPath + fileName); data.VendorFilePath2 = folderPath + fileName; data.VendorFileName2 = fileName; } } if (data.IsVendor3FileAttached) { int index = 3; if (!data.IsVendor2FileAttached) { index = index - 1; } if (!data.IsVendor1FileAttached) { index = index - 1; } if (!data.IsWorkOrderFileAttached) { index = index - 1; } fileName = Request.Files[index].FileName; if (!string.IsNullOrEmpty(data.VendorFilePath3) && data.IsVendor3FileAttached) { System.IO.File.Delete(data.VendorFilePath3); } if (!System.IO.File.Exists(folderPath + fileName)) { Request.Files[index].SaveAs(folderPath + fileName); data.VendorFilePath3 = folderPath + fileName; data.VendorFileName3 = fileName; } else { fileName = "1_" + Request.Files[index].FileName; if (!System.IO.File.Exists(folderPath + fileName)) { fileName = DateTime.Now.ToString("ddMMyyyHHmmsss") + "_3_" + Request.Files[index].FileName; } Request.Files[index].SaveAs(folderPath + fileName); data.VendorFilePath3 = folderPath + fileName; data.VendorFileName3 = fileName; } } } if (data.Id == 0) { result = _workOrderService.SaveOutward(data); } else { result = _workOrderService.UpdateOutward(data); } } catch (Exception ex) { return(Json(result, JsonRequestBehavior.AllowGet)); } return(Json(result, JsonRequestBehavior.AllowGet)); }