public ValidationMsg YearlyTargetRevisioned(PrqPurchaseYearTarget model, int userid) { _vmMsg = new ValidationMsg(); try { var originalEntity = _context.Prq_PurchaseYearPeriod.First(m => m.PeriodID == model.PeriodID); originalEntity.RecordStatus = "NCF"; foreach (PrqPurchaseYearPeriodItem objPrqPurchaseYearPeriodItem in model.PurchaseYearPeriodItemList) { objPrqPurchaseYearPeriodItem.PeriodID = model.PeriodID; objPrqPurchaseYearPeriodItem.SetBy = userid; Prq_PurchaseYearPeriodItemAudit tblPrqPurchaseYearPeriodItemAudit = SetToModelObjectAudit(objPrqPurchaseYearPeriodItem); _context.Prq_PurchaseYearPeriodItemAudit.Add(tblPrqPurchaseYearPeriodItemAudit); } _context.SaveChanges(); _vmMsg.Type = Enums.MessageType.Success; _vmMsg.Msg = "Revisioned Successfully."; } catch { _vmMsg.Type = Enums.MessageType.Error; _vmMsg.Msg = "Failed to Revisioned."; } return(_vmMsg); }
public PrqPurchaseYearTarget SetToBussinessObject(Prq_PurchaseYearTarget Entity) { PrqPurchaseYearTarget Model = new PrqPurchaseYearTarget(); Model.YearID = Entity.YearID; Model.PurchaseYear = Entity.PurchaseYear; Model.YearStartDate = Entity.YearStartDate.Date.ToString("dd/MM/yyyy"); Model.YearEndDate = Entity.YearEndDate.Date.ToString("dd/MM/yyyy"); Model.RecordStatus = Entity.RecordStatus; return(Model); }
public Prq_PurchaseYearTarget SetToModelObject(PrqPurchaseYearTarget model) { Prq_PurchaseYearTarget Entity = new Prq_PurchaseYearTarget(); Entity.YearStartDate = DalCommon.SetDate(model.YearStartDate); // Convert.ToDateTime(Convert.ToDateTime(model.YearStartDate).ToString("dd/MM/yyyy")); Entity.YearEndDate = DalCommon.SetDate(model.YearEndDate); //Convert.ToDateTime(Convert.ToDateTime(model.YearEndDate).ToString("dd/MM/yyyy")); Entity.PurchaseYear = model.PurchaseYear; Entity.SetOn = DateTime.Now; Entity.SetBy = model.SetBy; Entity.IPAddress = string.Empty; return(Entity); }
public ActionResult GetPeriodList(string yearId) { PrqPurchaseYearTarget model = new PrqPurchaseYearTarget(); int yearid = string.IsNullOrEmpty(yearId) ? 0 : Convert.ToInt32(yearId); var yearData = Dalobject.GetYearData(yearid); if (yearData != null) { model.PurchaseYearPeriodList = Dalobject.GetPeriodList(yearid); model.YearEndDate = yearData.FirstOrDefault().YearEndDate; model.YearStartDate = yearData.FirstOrDefault().YearStartDate; //model.YearStartDate = model.PurchaseYearPeriodList.Count > 0 ? model.PurchaseYearPeriodList[0].EndDate : yearData.FirstOrDefault().YearStartDate; model.PeriodID = model.PurchaseYearPeriodList.Count == 1 ? model.PurchaseYearPeriodList[0].PeriodID : 0; } return(Json(model, JsonRequestBehavior.AllowGet)); }
public ValidationMsg YearlyTargetConfirmed(PrqPurchaseYearTarget model, int userid) { _vmMsg = new ValidationMsg(); try { using (var tx = new TransactionScope()) { using (_context) { var originalEntityYear = _context.Prq_PurchaseYearTarget.First(m => m.YearID == model.YearID); originalEntityYear.RecordStatus = "CNF"; var originalEntity = _context.Prq_PurchaseYearPeriod.First(m => m.PeriodID == model.PeriodID); originalEntity.RecordStatus = "CNF"; if (model.PurchaseYearPeriodItemList != null) { foreach (PrqPurchaseYearPeriodItem objPrqPurchaseYearPeriodItem in model.PurchaseYearPeriodItemList) { var originalEntityItem = _context.Prq_PurchaseYearPeriodItem.First(m => m.PeriodItemID == objPrqPurchaseYearPeriodItem.PeriodItemID); originalEntityItem.RecordStatus = "CNF"; } } _context.SaveChanges(); tx.Complete(); _vmMsg.Type = Enums.MessageType.Success; _vmMsg.Msg = "Confirmed Successfully."; } } } catch { _vmMsg.Type = Enums.MessageType.Error; _vmMsg.Msg = "Failed to Confirmed."; } return(_vmMsg); }
public ActionResult YearlyTargetRevisioned(PrqPurchaseYearTarget model) { _vmMsg = Dalobject.YearlyTargetRevisioned(model, Convert.ToInt32(Session["UserID"])); return(Json(new { msg = _vmMsg })); }
public ActionResult PrqPurchaseYearPeriodItemv(PrqPurchaseYearTarget model) { _vmMsg = model.YearID == 0 ? Dalobject.Save(model, Convert.ToInt32(Session["UserID"])) : Dalobject.Update(model, Convert.ToInt32(Session["UserID"])); return(Json(new { YearID = Dalobject.GetYearID(), msg = _vmMsg })); }
public ValidationMsg Save(PrqPurchaseYearTarget model, int userid) { _vmMsg = new ValidationMsg(); try { IList <string> periodlist = new List <string>(); periodlist.Add(model.YearStartDate); foreach (var period in model.PeriodList) { periodlist.Add(period.StartDate.Contains("/") ? period.StartDate : Convert.ToDateTime(period.StartDate).ToString("dd/MM/yyyy")); periodlist.Add(period.EndDate.Contains("/") ? period.EndDate : Convert.ToDateTime(period.EndDate).ToString("dd/MM/yyyy")); } for (int i = 1; i <= periodlist.Count - 1; i++) { double day = (DalCommon.SetDate(periodlist[i]) - DalCommon.SetDate(periodlist[i - 1])).TotalDays; if (i != 1) { if (day <= 0) { error = 1; break; } } } if (error == 0) { #region Save using (var tx = new TransactionScope()) { using (_context) { var exitData = _context.Prq_PurchaseYearTarget.Where(m => m.PurchaseYear == model.PurchaseYear).ToList(); if (exitData.Count > 0) { _vmMsg.Type = Enums.MessageType.Error; _vmMsg.Msg = "Alreary Exit This Year."; } else { model.SetBy = userid; Prq_PurchaseYearTarget tblPurchaseYearTarget = SetToModelObject(model); _context.Prq_PurchaseYearTarget.Add(tblPurchaseYearTarget); _context.SaveChanges(); #region Save Period Records if (model.PurchaseYearPeriodList != null) { foreach (PrqPurchaseYearPeriod objPrqPurchaseYearPeriod in model.PurchaseYearPeriodList) { ////var yearStartDate = Convert.ToDateTime(objPrqPurchaseYearPeriod.StartDate).Date; ////var yearEndDate = Convert.ToDateTime(objPrqPurchaseYearPeriod.EndDate).Date; //objPrqPurchaseYearPeriod.SetBy = userid; //objPrqPurchaseYearPeriod.StartDate = // Convert.ToDateTime(objPrqPurchaseYearPeriod.StartDate) // .Date.ToString("dd/MM/yyyy"); //objPrqPurchaseYearPeriod.EndDate = // Convert.ToDateTime(objPrqPurchaseYearPeriod.EndDate) // .Date.ToString("dd/MM/yyyy"); objPrqPurchaseYearPeriod.StartDate = objPrqPurchaseYearPeriod.StartDate.Contains("/") ? objPrqPurchaseYearPeriod.StartDate : Convert.ToDateTime(objPrqPurchaseYearPeriod.StartDate).ToString("dd/MM/yyyy"); objPrqPurchaseYearPeriod.EndDate = objPrqPurchaseYearPeriod.EndDate.Contains("/") ? objPrqPurchaseYearPeriod.EndDate : Convert.ToDateTime(objPrqPurchaseYearPeriod.EndDate).ToString("dd/MM/yyyy"); objPrqPurchaseYearPeriod.YearID = tblPurchaseYearTarget.YearID; Prq_PurchaseYearPeriod tblPurchaseYearPeriod = SetToModelObject(objPrqPurchaseYearPeriod); _context.Prq_PurchaseYearPeriod.Add(tblPurchaseYearPeriod); _context.SaveChanges(); #region Save Period Item List if (model.PurchaseYearPeriodItemList != null) { foreach ( PrqPurchaseYearPeriodItem objPrqPurchaseYearPeriodItem in model.PurchaseYearPeriodItemList) { objPrqPurchaseYearPeriodItem.PeriodID = tblPurchaseYearPeriod.PeriodID; objPrqPurchaseYearPeriodItem.SetBy = userid; Prq_PurchaseYearPeriodItem tblPurchaseYearPeriodItem = SetToModelObject(objPrqPurchaseYearPeriodItem); _context.Prq_PurchaseYearPeriodItem.Add(tblPurchaseYearPeriodItem); } } #endregion } } _context.SaveChanges(); #endregion tx.Complete(); YearID = tblPurchaseYearTarget.YearID; _vmMsg.Type = Enums.MessageType.Success; _vmMsg.Msg = "Saved Successfully."; } } } #endregion } else { _vmMsg.Type = Enums.MessageType.Error; _vmMsg.Msg = "Period is not Properly Define."; } } catch { _vmMsg.Type = Enums.MessageType.Error; _vmMsg.Msg = "Failed to save."; } return(_vmMsg); }
public ValidationMsg Update(PrqPurchaseYearTarget model, int userid) { _vmMsg = new ValidationMsg(); try { IList <string> periodlist = new List <string>(); periodlist.Add(model.YearStartDate); foreach (var period in model.PeriodList) { periodlist.Add(period.StartDate.Contains("/") ? period.StartDate : Convert.ToDateTime(period.StartDate).ToString("dd/MM/yyyy")); periodlist.Add(period.EndDate.Contains("/") ? period.EndDate : Convert.ToDateTime(period.EndDate).ToString("dd/MM/yyyy")); } for (int i = 1; i <= periodlist.Count - 1; i++) { double day = (DalCommon.SetDate(periodlist[i]) - DalCommon.SetDate(periodlist[i - 1])).TotalDays; if (day < 0) { error = 1; break; } } if (error == 0) { #region Update using (var tx = new TransactionScope()) { using (_context) { Prq_PurchaseYearTarget CurrentEntity = SetToModelObject(model); var OriginalEntity = _context.Prq_PurchaseYearTarget.First(m => m.YearID == model.YearID); OriginalEntity.PurchaseYear = CurrentEntity.PurchaseYear; OriginalEntity.YearStartDate = CurrentEntity.YearStartDate; OriginalEntity.YearEndDate = CurrentEntity.YearEndDate; OriginalEntity.ModifiedBy = userid; OriginalEntity.ModifiedOn = DateTime.Now; #region Save Period Records if (model.PurchaseYearPeriodList != null) { foreach (PrqPurchaseYearPeriod objPrqPurchaseYearPeriod in model.PurchaseYearPeriodList) { objPrqPurchaseYearPeriod.StartDate = objPrqPurchaseYearPeriod.StartDate.Contains("/") ? objPrqPurchaseYearPeriod.StartDate : Convert.ToDateTime(objPrqPurchaseYearPeriod.StartDate).ToString("dd/MM/yyyy"); objPrqPurchaseYearPeriod.EndDate = objPrqPurchaseYearPeriod.EndDate.Contains("/") ? objPrqPurchaseYearPeriod.EndDate : Convert.ToDateTime(objPrqPurchaseYearPeriod.EndDate).ToString("dd/MM/yyyy"); //objPrqPurchaseYearPeriod.StartDate = // Convert.ToDateTime(objPrqPurchaseYearPeriod.StartDate) // .Date.ToString("dd/MM/yyyy"); //objPrqPurchaseYearPeriod.EndDate = // Convert.ToDateTime(objPrqPurchaseYearPeriod.EndDate) // .Date.ToString("dd/MM/yyyy"); if (objPrqPurchaseYearPeriod.PeriodID == 0) { objPrqPurchaseYearPeriod.YearID = model.YearID; objPrqPurchaseYearPeriod.SetBy = userid; Prq_PurchaseYearPeriod tblPurchaseYearPeriod = SetToModelObject(objPrqPurchaseYearPeriod); _context.Prq_PurchaseYearPeriod.Add(tblPurchaseYearPeriod); PeriodID = tblPurchaseYearPeriod.PeriodID; } else { Prq_PurchaseYearPeriod CurEntity = SetToModelObject(objPrqPurchaseYearPeriod); var OrgEntity = _context.Prq_PurchaseYearPeriod.First(m => m.PeriodID == objPrqPurchaseYearPeriod.PeriodID); OrgEntity.StartDate = CurEntity.StartDate; OrgEntity.EndDate = CurEntity.EndDate; OrgEntity.ModifiedBy = userid; OrgEntity.ModifiedOn = DateTime.Now; } #region Save Period Item List if (model.PurchaseYearPeriodItemList != null) { foreach ( PrqPurchaseYearPeriodItem objPrqPurchaseYearPeriodItem in model.PurchaseYearPeriodItemList) { if (objPrqPurchaseYearPeriodItem.PeriodItemID == 0) { objPrqPurchaseYearPeriodItem.PeriodID = PeriodID; objPrqPurchaseYearPeriodItem.SetBy = userid; Prq_PurchaseYearPeriodItem tblPurchaseYearPeriodItem = SetToModelObject(objPrqPurchaseYearPeriodItem); _context.Prq_PurchaseYearPeriodItem.Add(tblPurchaseYearPeriodItem); } else { Prq_PurchaseYearPeriodItem CurrEntity = SetToModelObject(objPrqPurchaseYearPeriodItem); var OrgrEntity = _context.Prq_PurchaseYearPeriodItem.First( m => m.PeriodItemID == objPrqPurchaseYearPeriodItem.PeriodItemID); OrgrEntity.ItemTypeID = CurrEntity.ItemTypeID; OrgrEntity.LeatherType = CurrEntity.LeatherType; OrgrEntity.LeatherStatus = CurrEntity.LeatherStatus; OrgrEntity.SizeID = CurrEntity.SizeID; OrgrEntity.TargetQuantity = CurrEntity.TargetQuantity; OrgrEntity.UnitID = CurrEntity.UnitID; OrgrEntity.TargetValue = CurrEntity.TargetValue; OrgrEntity.CurrencyID = CurrEntity.CurrencyID; OrgrEntity.RecordStatus = CurrEntity.RecordStatus; } } } #endregion } } else { #region Save Period Item List if (model.PurchaseYearPeriodItemList != null) { foreach ( PrqPurchaseYearPeriodItem objPrqPurchaseYearPeriodItem in model.PurchaseYearPeriodItemList) { if (objPrqPurchaseYearPeriodItem.PeriodItemID == 0) { objPrqPurchaseYearPeriodItem.PeriodID = model.PeriodID; Prq_PurchaseYearPeriodItem tblPurchaseYearPeriodItem = SetToModelObject(objPrqPurchaseYearPeriodItem); _context.Prq_PurchaseYearPeriodItem.Add(tblPurchaseYearPeriodItem); } else { Prq_PurchaseYearPeriodItem CurrEntity = SetToModelObject(objPrqPurchaseYearPeriodItem); var OrgrEntity = _context.Prq_PurchaseYearPeriodItem.First( m => m.PeriodItemID == objPrqPurchaseYearPeriodItem.PeriodItemID); OrgrEntity.ItemTypeID = CurrEntity.ItemTypeID; OrgrEntity.LeatherType = CurrEntity.LeatherType; OrgrEntity.LeatherStatus = CurrEntity.LeatherStatus; OrgrEntity.SizeID = CurrEntity.SizeID; OrgrEntity.TargetQuantity = CurrEntity.TargetQuantity; OrgrEntity.UnitID = CurrEntity.UnitID; OrgrEntity.TargetValue = CurrEntity.TargetValue; OrgrEntity.CurrencyID = CurrEntity.CurrencyID; OrgrEntity.RecordStatus = CurrEntity.RecordStatus; } } } #endregion } _context.SaveChanges(); #endregion tx.Complete(); _vmMsg.Type = Enums.MessageType.Update; _vmMsg.Msg = "Updated Successfully."; } } #endregion } else { _vmMsg.Type = Enums.MessageType.Error; _vmMsg.Msg = "Period is not Properly Define."; } } catch { _vmMsg.Type = Enums.MessageType.Error; _vmMsg.Msg = "Failed to Update."; } return(_vmMsg); }