public bool AddDocument(VoucherDocument voucherDocument) { try { voucherDocument.State = ObjectState.Added; _crudOperation.AddOperation(voucherDocument); voucherDocument.State = ObjectState.Unchanged; return true; } catch (Exception ex) { var rr = ex.Message; return false; } }
public bool UpdateDocumentVoucher(VoucherDocument voucherDocument) { try { var dbObj = _crudOperation.GetSingleObject(voucherDocument.Id); dbObj.Description = voucherDocument.Description; voucherDocument.State = ObjectState.Modified; _crudOperation.UpdateOperation(dbObj); return true; } catch (Exception ex) { var rr = ex.Message; return false; } }
public ActionResult RepeatingJournal(VoucherCustom vc) { VoucherCustom v = vc; Voucher voucher = vc.voucher; var vtObj = _voucherType.GetVoucherTypeByCode("04"); if (vtObj != null) { voucher.VoucherTypeId = vtObj.Id; } else { TempData.Add("errMsg", "Please Add voucher type as RepeatingJournal with 04 Code."); return RedirectToAction("RepeatingJournal", "Voucher", new { area = "Accounts" }); } var user = _uService.GetSingleUserByEmail(HttpContext.User.Identity.Name); var accSet = _sService.GetAllByUserId(user.Id); var empObj = _empService.GetEmployeeByUserIdAndCompanyId(user.Id, (int)accSet.CompanyId); if (empObj != null) { voucher.EmployeeId = empObj.Id; } else { TempData.Add("errMsg", "User must be a employee for this Transaction."); return RedirectToAction("RepeatingJournal", "Voucher", new { area = "Accounts" }); //return Content("User must be a employee for this Transaction."); } if (accSet.CompanyId != null) voucher.BranchId = (int)accSet.CompanyId; if (Request.Form["post"] != null) { voucher.Posted = 1; } else if (Request.Form["draft"] != null) { voucher.Posted = 0; } voucher.BillNo = Request.Form["billnop1"] + " " + Request.Form["billnop2"]; //I have no Idea why?? if (_vService.CreateVoucher(voucher)) { List<VoucherDetail> vds = vc.voucherDetails; foreach (var voucherDetail in vds) { voucherDetail.VoucherId = voucher.Id; try { if (!_vdService.CreateVoucherDetail(voucherDetail)) { TempData.Add("errMsg", "One or more Voucher details could not added Successfully"); return RedirectToAction("RepeatingJournal", "Voucher", new { area = "Accounts" }); } // return Content("One or more Voucher details could not added Successfully"); } catch (Exception) { TempData.Add("errMsg", "Voucher Details problem"); return RedirectToAction("RepeatingJournal", "Voucher", new { area = "Accounts" }); //return Content("Voucher Details problem"); } } string data = Request.Form["note_data"]; if (Request.Form["note_data"] != "") { JArray noteData = JArray.Parse(data); var VDoc = new VoucherDocument(); for (int i = 0; i < noteData.Count(); i++) { VDoc.CreatedDate = Convert.ToDateTime(noteData[i]["date"].ToString()); VDoc.Description = noteData[i]["des"].ToString(); VDoc.DocumentType = noteData[i]["type"].ToString(); VDoc.EmployeeId = empObj.Id; VDoc.VoucherId = voucher.Id; _vDocSar.AddDocument(VDoc); } } string documentName; string documentLocation; for (int i = 0; i < Request.Files.Count; i++) { if ("documentLocation[]" == Request.Files.GetKey(i)) { documentName = "Document_" + voucher.Id + "_" + i + Path.GetRandomFileName() + Path.GetExtension(Request.Files[i].FileName); documentLocation = Server.MapPath("~/Uploads/" + accSet.Companies.TradingName.Replace(" ", "_") + "/VoucherDocuments/"); if (fileUpload(Request.Files[i], documentName, documentLocation)) { VoucherDocument VDoc = new VoucherDocument(); VDoc.CreatedDate = DateTime.Now; VDoc.DocumentType = "File"; VDoc.EmployeeId = empObj.Id; VDoc.VoucherId = voucher.Id; VDoc.FileLocation = "Uploads/" + accSet.Companies.TradingName.Replace(" ", "_") + "/VoucherDocuments/"+ documentName; _vDocSar.AddDocument(VDoc); } } } } else { TempData.Add("errMsg", "Failed To Add Voucher"); return RedirectToAction("RepeatingJournal", "Voucher", new { area = "Accounts" }); //return Content("Failed To Add Voucher!!!!"); } TempData.Add("SucMasg", "Voucher Added Successfully"); return RedirectToAction("ManualJournals"); }