public ActionResult DeletePost(LedgerAccountOpeningViewModel vm) { LedgerHeader Header = new LedgerHeaderService(_unitOfWork).Find(vm.LedgerHeaderId); LedgerLine Line = new LedgerLineService(_unitOfWork).FindByLedgerHeader(vm.LedgerHeaderId).FirstOrDefault(); Ledger Ledger = new LedgerService(_unitOfWork).FindForLedgerHeader(vm.LedgerHeaderId).FirstOrDefault(); Ledger LedgerToDelete = db.Ledger.Find(Ledger.LedgerId); LedgerLine LedgerLineToDelete = db.LedgerLine.Find(Line.LedgerLineId); LedgerHeader LedgerHeaderToDelete = db.LedgerHeader.Find(Header.LedgerHeaderId); LedgerToDelete.ObjectState = Model.ObjectState.Deleted; db.Ledger.Remove(LedgerToDelete); LedgerLineToDelete.ObjectState = Model.ObjectState.Deleted; db.LedgerLine.Remove(LedgerLineToDelete); LedgerHeaderToDelete.ObjectState = Model.ObjectState.Deleted; db.LedgerHeader.Remove(LedgerHeaderToDelete); try { db.SaveChanges(); } catch (Exception ex) { string message = _exception.HandleException(ex); PrepareViewBag(); ModelState.AddModelError("", message); return(PartialView("EditSize", vm)); } return(Json(new { success = true })); }
public ActionResult _CreatePost(LedgerAccountOpeningViewModel svm) { if (ModelState.IsValid) { if (svm.LedgerHeaderId <= 0) { var temp = (from H in db.LedgerHeader where H.DocTypeId == svm.DocTypeId && H.DocNo == svm.DocNo && H.SiteId == svm.SiteId && H.DivisionId == svm.DivisionId select H).FirstOrDefault(); if (temp != null) { if (svm.LedgerSetting.IsAutoDocNo == true) { svm.DocNo = new DocumentTypeService(_unitOfWork).FGetNewDocNo("DocNo", ConfigurationManager.AppSettings["DataBaseSchema"] + ".LedgerHeaders", svm.DocTypeId, svm.DocDate, svm.DivisionId, svm.SiteId); } } } if (svm.LedgerHeaderId == 0) { LedgerHeader Header = new LedgerHeader(); Header.DocHeaderId = svm.LedgerAccountId; Header.DocNo = svm.DocNo; Header.DocTypeId = svm.DocTypeId; Header.DocDate = svm.DocDate; Header.SiteId = svm.SiteId; Header.DivisionId = svm.DivisionId; Header.PaymentFor = null; Header.AdjustmentType = null; Header.ProcessId = null; Header.GodownId = null; Header.LedgerAccountId = null; Header.DrCr = null; Header.PartyDocNo = svm.PartyDocNo; Header.PartyDocDate = svm.PartyDocDate; Header.Narration = svm.Narration; Header.CreatedDate = DateTime.Now; Header.CreatedBy = User.Identity.Name; Header.ModifiedDate = DateTime.Now; Header.ModifiedBy = User.Identity.Name; Header.ObjectState = Model.ObjectState.Added; db.LedgerHeader.Add(Header); LedgerLine Line = new LedgerLine(); Line.LedgerHeaderId = Header.LedgerHeaderId; Line.LedgerAccountId = svm.LedgerAccountId; Line.Amount = svm.Amount; Line.ChqNo = null; Line.ChqDate = null; Line.CostCenterId = null; Line.BaseRate = 0; Line.BaseValue = 0; Line.ReferenceId = null; Line.ProductUidId = null; Line.ReferenceDocTypeId = null; Line.ReferenceDocId = null; Line.CreatedDate = DateTime.Now; Line.ModifiedDate = DateTime.Now; Line.CreatedBy = User.Identity.Name; Line.Remark = svm.Narration; Line.ModifiedBy = User.Identity.Name; Line.ObjectState = Model.ObjectState.Added; db.LedgerLine.Add(Line); Ledger Ledger = new Ledger(); if (svm.DrCr == NatureConstants.Debit) { Ledger.AmtDr = svm.Amount; } else if (svm.DrCr == NatureConstants.Credit) { Ledger.AmtCr = svm.Amount; } Ledger.ChqNo = Line.ChqNo; Ledger.ContraLedgerAccountId = null; Ledger.CostCenterId = Line.CostCenterId; Ledger.DueDate = null; Ledger.LedgerAccountId = Line.LedgerAccountId; Ledger.LedgerHeaderId = Line.LedgerHeaderId; Ledger.LedgerLineId = Line.LedgerLineId; Ledger.ProductUidId = Line.ProductUidId; Ledger.Narration = Header.Narration; Ledger.ObjectState = Model.ObjectState.Added; Ledger.LedgerId = 1; db.Ledger.Add(Ledger); try { db.SaveChanges(); } catch (Exception ex) { string message = _exception.HandleException(ex); PrepareViewBag(); ModelState.AddModelError("", message); return(PartialView("_Create", svm)); } return(RedirectToAction("_Create", new { id = svm.LedgerAccountId })); } else { LedgerHeader Header = new LedgerHeaderService(_unitOfWork).Find(svm.LedgerHeaderId); LedgerLine Line = new LedgerLineService(_unitOfWork).FindByLedgerHeader(svm.LedgerHeaderId).FirstOrDefault(); Ledger Ledger = new LedgerService(_unitOfWork).FindForLedgerHeader(svm.LedgerHeaderId).FirstOrDefault(); Header.SiteId = svm.SiteId; Header.DivisionId = svm.DivisionId; Header.DocNo = svm.DocNo; Header.DocTypeId = svm.DocTypeId; Header.DocDate = svm.DocDate; Header.PartyDocNo = svm.PartyDocNo; Header.PartyDocDate = svm.PartyDocDate; Header.Narration = svm.Narration; Header.ModifiedDate = DateTime.Now; Header.ModifiedBy = User.Identity.Name; Header.ObjectState = Model.ObjectState.Modified; db.LedgerHeader.Add(Header); Line.Amount = svm.Amount; Line.ModifiedDate = DateTime.Now; Line.ModifiedBy = User.Identity.Name; Line.ObjectState = Model.ObjectState.Modified; db.LedgerLine.Add(Line); if (svm.DrCr == NatureConstants.Debit) { Ledger.AmtDr = svm.Amount; Ledger.AmtCr = 0; } else if (svm.DrCr == NatureConstants.Credit) { Ledger.AmtCr = svm.Amount; Ledger.AmtDr = 0; } Ledger.ChqNo = Line.ChqNo; Ledger.CostCenterId = Line.CostCenterId; Ledger.LedgerAccountId = Line.LedgerAccountId; Ledger.LedgerHeaderId = Line.LedgerHeaderId; Ledger.LedgerLineId = Line.LedgerLineId; Ledger.ProductUidId = Line.ProductUidId; Ledger.Narration = Header.Narration; Ledger.ObjectState = Model.ObjectState.Modified; db.Ledger.Add(Ledger); try { db.SaveChanges(); } catch (Exception ex) { string message = _exception.HandleException(ex); PrepareViewBag(); ModelState.AddModelError("", message); return(PartialView("_Create", svm)); } return(Json(new { success = true })); } } PrepareViewBag(); return(PartialView("_Create", svm)); }