public ActionResult Insert(ValuatorOneViewModel objViewModel) { try { ModelState.Remove("Id"); if (objViewModel.ID == 0) { if (InsertData(objViewModel)) { return(Json(1, JsonRequestBehavior.AllowGet)); } else { return(Json(3, JsonRequestBehavior.AllowGet)); } } else { if (InsertData(objViewModel)) { return(Json(2, JsonRequestBehavior.AllowGet)); } } objViewModel.ValuatorOneDetailsList = new List <ValuatorOneDetailsViewModel>(); ViewBag.PurityList = new SelectList(_valuatorOneService.GetAllPurityMaster(), "Id", "PurityName"); ViewBag.OrnamentList = new SelectList(_valuatorOneService.GetOrnamentList(), "ItemId", "ItemName"); return(View("ValuatorOne", objViewModel)); } catch (Exception ex) { throw ex; } }
public ValuatorOneViewModel GetMaxTransactionId() { var model = new ValuatorOneViewModel(); var transactionid = _context.tbl_ValuatorOne.Any() ? _context.tbl_ValuatorOne.Max(x => x.Id) + 1 : 1; model.TransactionId = "VO0000" + transactionid; return(model); }
public ActionResult ValuatorOne() { ButtonVisiblity("Index"); var model = new ValuatorOneViewModel(); model = _valuatorOneService.GetMaxTransactionId(); ViewBag.PurityList = new SelectList(_valuatorOneService.GetAllPurityMaster(), "Id", "PurityName"); ViewBag.OrnamentList = new SelectList(_valuatorOneService.GetOrnamentList(), "ItemId", "ItemName"); Session["ValuationImageList"] = null; Session["ConsolidatedImage"] = null; Session["ConsolidatedImageName"] = null; Session["ConsolidatedImageContentType"] = null; return(View(model)); }
public ValuatorOneViewModel GetValuatorOneDetailsById(int Id) { var model = new ValuatorOneViewModel(); model = (from a in _context.tbl_ValuatorOne join b in _context.TGLPreSanctions on a.PreSanctionId equals b.PreSanctionID where a.Id == Id select new ValuatorOneViewModel() { ID = a.Id, KycId = a.KYCId, TransactionId = a.TransactionId, CustomerId = a.CustomerID, ApplicationNo = a.ApplicationNo, Comments = a.Comments, ImageName = a.ImageName ?? "", ProductId = b.ProductID, PreSanctionId = (int)a.PreSanctionId }).FirstOrDefault(); var valuatoronedetails = (from a in _context.tbl_ValuatorOne join b in _context.tbl_ValuatorOneDetails on a.Id equals b.ValuationOneID join c in _context.tblItemMasters on b.OrnamentId equals c.ItemID join d in _context.Mst_PurityMaster on b.PurityId equals d.id where b.ValuationOneID == Id select new ValuatorOneDetailsViewModel() { ID = b.Id, ValuatorOneId = b.ValuationOneID, OrnamentId = b.OrnamentId, OrnamentName = c.ItemName, ImageName = b.ImageName ?? "", Qty = (int)b.Qty, PurityId = b.PurityId, PurityName = d.PurityName, GrossWeight = (decimal)b.GrossWt, Deductions = (decimal)b.Deduction, NetWeight = (decimal)b.NtWt, Rate = (decimal)b.Rate, Total = (decimal)b.Total }).ToList(); model.ValuatorOneDetailsList = valuatoronedetails; return(model); }
public bool InsertData(ValuatorOneViewModel model) { bool retVal = false; model.CreatedBy = Convert.ToInt32(Session["UserLoginId"]); model.UpdatedBy = Convert.ToInt32(Session["UserLoginId"]); try { if (Session["ConsolidatedImage"] != null) { model.ConsolidatedImageFile = (byte[])Session["ConsolidatedImage"]; model.ImageName = Session["ConsolidatedImageName"].ToString(); model.ContentType = Session["ConsolidatedImageContentType"].ToString(); } if (Session["ValuationImageList"] != null) { var list = (List <ValuatorOneDetailsViewModel>)Session["ValuationImageList"]; if (list != null) { for (int i = 0; i <= list.Count - 1; i++) { model.ValuatorOneDetailsList[i].ValuationImageFile = list[i].ValuationImageFile; model.ValuatorOneDetailsList[i].ImageName = list[i].ImageName; model.ValuatorOneDetailsList[i].ContentType = list[i].ContentType; } } } _valuatorOneService.SaveRecord(model); retVal = true; } catch (Exception ex) { throw ex; } return(retVal); }
public void SaveRecord(ValuatorOneViewModel model) { _valuatorOneRepository.SaveUpdateRecord(model); }
public void SaveUpdateRecord(ValuatorOneViewModel model) { tbl_ValuatorOne tblValOne = new tbl_ValuatorOne(); try { if (model.ID <= 0) { //save the data in Document Upload Details table tblValOne.TransactionId = model.TransactionId; tblValOne.KYCId = model.KycId; tblValOne.PreSanctionId = model.PreSanctionId; tblValOne.CustomerID = model.CustomerId; tblValOne.ApplicationNo = model.ApplicationNo; tblValOne.Comments = model.Comments; tblValOne.BranchId = Convert.ToInt32(HttpContext.Current.Session["BranchId"]); tblValOne.CompId = Convert.ToInt32(HttpContext.Current.Session["CompanyId"]); tblValOne.FinancialYearId = Convert.ToInt32(HttpContext.Current.Session["FinancialYearId"]); tblValOne.CreatedBy = model.CreatedBy; tblValOne.CreatedDate = DateTime.Now; tblValOne.UpdatedBy = model.UpdatedBy; tblValOne.UpdatedDate = DateTime.Now; tblValOne.ConsolidatedImage = model.ConsolidatedImageFile; tblValOne.ImageName = model.ImageName; tblValOne.ContentType = model.ContentType; _context.tbl_ValuatorOne.Add(tblValOne); _context.SaveChanges(); int maxid = _context.tbl_ValuatorOne.Any() ? _context.tbl_ValuatorOne.Max(x => x.Id) : 1; foreach (var p in model.ValuatorOneDetailsList) { var trn = new tbl_ValuatorOneDetails { ValuationOneID = maxid, OrnamentId = p.OrnamentId, OrnamentImage = p.ValuationImageFile, ImageName = p.ImageName, ContentType = p.ContentType, Qty = p.Qty, PurityId = p.PurityId, GrossWt = p.GrossWeight, Deduction = p.Deductions, NtWt = p.NetWeight, Rate = p.Rate, Total = p.Total, }; _context.tbl_ValuatorOneDetails.Add(trn); _context.SaveChanges(); } } else { //update the data in Charge Details table var tblObj = _context.tbl_ValuatorOne.Where(x => x.Id == model.ID).FirstOrDefault(); tblObj.PreSanctionId = model.PreSanctionId; tblObj.KYCId = model.KycId; tblObj.TransactionId = model.TransactionId.ToString(); tblObj.CustomerID = model.CustomerId; tblObj.ApplicationNo = model.ApplicationNo; tblObj.Comments = model.Comments; tblObj.UpdatedBy = model.CreatedBy; tblObj.UpdatedDate = DateTime.Now; tblObj.BranchId = Convert.ToInt32(HttpContext.Current.Session["BranchId"]); tblObj.CompId = Convert.ToInt32(HttpContext.Current.Session["CompanyId"]); tblObj.FinancialYearId = Convert.ToInt32(HttpContext.Current.Session["FinancialYearId"]); tblObj.ConsolidatedImage = model.ConsolidatedImageFile; tblObj.ImageName = model.ImageName; tblObj.ContentType = model.ContentType; _context.SaveChanges(); List <tbl_ValuatorOneDetails> NewtblDetails = new List <tbl_ValuatorOneDetails>(); //update the data in Charge Details table foreach (var p in model.ValuatorOneDetailsList) { var Findobject = _context.tbl_ValuatorOneDetails.Where(x => x.ValuationOneID == model.ID && x.Id == p.ID).FirstOrDefault(); if (Findobject == null) { var trn = new tbl_ValuatorOneDetails { ValuationOneID = model.ID, OrnamentId = p.OrnamentId, OrnamentImage = p.ValuationImageFile, ImageName = p.ImageName, ContentType = p.ContentType, Qty = p.Qty, PurityId = p.PurityId, GrossWt = p.GrossWeight, Deduction = p.Deductions, NtWt = p.NetWeight, Rate = p.Rate, Total = p.Total }; _context.tbl_ValuatorOneDetails.Add(trn); } else { Findobject.ValuationOneID = tblObj.Id; Findobject.OrnamentId = p.OrnamentId; Findobject.OrnamentImage = p.ValuationImageFile; Findobject.ContentType = p.ContentType; Findobject.ImageName = p.ImageName; Findobject.Qty = p.Qty; Findobject.PurityId = p.PurityId; Findobject.GrossWt = p.GrossWeight; Findobject.Deduction = p.Deductions; Findobject.NtWt = p.NetWeight; Findobject.Rate = p.Rate; Findobject.Total = p.Total; } NewtblDetails.Add(Findobject); } #region product rate details remove //take the loop of table and check from list if found in list then not remove else remove from table itself var trnobjlist = _context.tbl_ValuatorOneDetails.Where(x => x.ValuationOneID == model.ID).ToList(); if (trnobjlist != null) { foreach (tbl_ValuatorOneDetails item in trnobjlist) { if (NewtblDetails.Contains(item)) { continue; } else { _context.tbl_ValuatorOneDetails.Remove(item); } } _context.SaveChanges(); } #endregion trn remove } } catch (Exception ex) { throw ex; } }