Ejemplo n.º 1
0
        public JsonResult SetExpenseBudgetForUpdate(List <ExpenseBudgetModel> lstExpenseBudgetMaster, List <ExpenseBudgetDetailViewModel> lstExpenseBudgetDetails, string UpdateId)
        {
            var strMessage = string.Empty;

            // Clear detail list
            //Session["lstSampleRequestDetails"] = null;

            try
            {
                if (ModelState.IsValid)
                {
                    Int64 Id    = Convert.ToInt64(UpdateId);
                    var   model = _ExpenseBudgetService.BMSUnit.ExpenseBudgetRepository.GetByID(Id);



                    List <SalesBudgetModel> masterList = new List <SalesBudgetModel>();

                    foreach (var item in lstExpenseBudgetMaster)
                    {
                        ExpenseBudgetModel masterEntityModel = new ExpenseBudgetModel();

                        #region Current User
                        var userName = HttpContext.User.Identity.Name;
                        masterEntityModel.IUser = model.IUser;
                        masterEntityModel.IDate = model.IDate;
                        masterEntityModel.EUser = userName;
                        masterEntityModel.EDate = DateTime.Now;
                        #endregion
                        masterEntityModel.SalesPersonId = item.SalesPersonId;
                        masterEntityModel.DivisionId    = item.DivisionId;
                        masterEntityModel.SBUId         = item.SBUId;
                        masterEntityModel.BudgetYear    = item.BudgetYear;
                        masterEntityModel.Id            = Id;
                        //masterList.Add(masterEntityModel);

                        var entity = masterEntityModel.ToEntity();
                        _ExpenseBudgetService.BMSUnit.ExpenseBudgetRepository.Update(entity);
                        _ExpenseBudgetService.BMSUnit.ExpenseBudgetRepository.SaveChanges();

                        Session["ExpenseBudgetUpdateId"] = entity.Id;
                    }

                    var lst = _ExpenseBudgetService.BMSUnit.ExpenseBudgetDetailRepository.GetAll().Where(
                        q => q.ExpenseBudgetId == Convert.ToInt64(Session["ExpenseBudgetUpdateId"]));

                    foreach (var dt in lst)
                    {
                        _ExpenseBudgetService.BMSUnit.ExpenseBudgetDetailRepository.Delete_64Bit(Convert.ToInt64(dt.Id));
                    }


                    // Add new detail information

                    foreach (var item in lstExpenseBudgetDetails)
                    {
                        ExpenseBudgetDetail entityDetailModel = new ExpenseBudgetDetail();

                        entityDetailModel.ExpenseBudgetId = Convert.ToInt64(Convert.ToInt64(Session["ExpenseBudgetUpdateId"]));
                        entityDetailModel.ParticularId    = item.ParticularId;
                        entityDetailModel.BudgetMonth     = 1;
                        entityDetailModel.Value           = item.JanVal;

                        var detailEntityjan = entityDetailModel.ToEntity();
                        _ExpenseBudgetService.BMSUnit.ExpenseBudgetDetailRepository.Add(detailEntityjan);
                        _ExpenseBudgetService.BMSUnit.ExpenseBudgetDetailRepository.SaveChanges();

                        entityDetailModel.ExpenseBudgetId = Convert.ToInt64(Convert.ToInt64(Session["ExpenseBudgetUpdateId"]));
                        entityDetailModel.ParticularId    = item.ParticularId;
                        entityDetailModel.BudgetMonth     = 2;
                        entityDetailModel.Value           = item.FebVal;

                        var detailEntityFeb = entityDetailModel.ToEntity();
                        _ExpenseBudgetService.BMSUnit.ExpenseBudgetDetailRepository.Add(detailEntityFeb);
                        _ExpenseBudgetService.BMSUnit.ExpenseBudgetDetailRepository.SaveChanges();

                        entityDetailModel.ExpenseBudgetId = Convert.ToInt64(Convert.ToInt64(Session["ExpenseBudgetUpdateId"]));
                        entityDetailModel.ParticularId    = item.ParticularId;
                        entityDetailModel.BudgetMonth     = 3;
                        entityDetailModel.Value           = item.MarVal;

                        var detailEntityMarch = entityDetailModel.ToEntity();
                        _ExpenseBudgetService.BMSUnit.ExpenseBudgetDetailRepository.Add(detailEntityMarch);
                        _ExpenseBudgetService.BMSUnit.ExpenseBudgetDetailRepository.SaveChanges();

                        entityDetailModel.ExpenseBudgetId = Convert.ToInt64(Convert.ToInt64(Session["ExpenseBudgetUpdateId"]));
                        entityDetailModel.ParticularId    = item.ParticularId;
                        entityDetailModel.BudgetMonth     = 4;
                        entityDetailModel.Value           = item.AprVal;

                        var detailEntityApril = entityDetailModel.ToEntity();
                        _ExpenseBudgetService.BMSUnit.ExpenseBudgetDetailRepository.Add(detailEntityApril);
                        _ExpenseBudgetService.BMSUnit.ExpenseBudgetDetailRepository.SaveChanges();

                        entityDetailModel.ExpenseBudgetId = Convert.ToInt64(Convert.ToInt64(Session["ExpenseBudgetUpdateId"]));
                        entityDetailModel.ParticularId    = item.ParticularId;
                        entityDetailModel.BudgetMonth     = 5;
                        entityDetailModel.Value           = item.MayVal;

                        var detailEntityMay = entityDetailModel.ToEntity();
                        _ExpenseBudgetService.BMSUnit.ExpenseBudgetDetailRepository.Add(detailEntityMay);
                        _ExpenseBudgetService.BMSUnit.ExpenseBudgetDetailRepository.SaveChanges();

                        entityDetailModel.ExpenseBudgetId = Convert.ToInt64(Convert.ToInt64(Session["ExpenseBudgetUpdateId"]));
                        entityDetailModel.ParticularId    = item.ParticularId;
                        entityDetailModel.BudgetMonth     = 6;
                        entityDetailModel.Value           = item.JunVal;

                        var detailEntityJun = entityDetailModel.ToEntity();
                        _ExpenseBudgetService.BMSUnit.ExpenseBudgetDetailRepository.Add(detailEntityJun);
                        _ExpenseBudgetService.BMSUnit.ExpenseBudgetDetailRepository.SaveChanges();

                        entityDetailModel.ExpenseBudgetId = Convert.ToInt64(Convert.ToInt64(Session["ExpenseBudgetUpdateId"]));
                        entityDetailModel.ParticularId    = item.ParticularId;
                        entityDetailModel.BudgetMonth     = 7;
                        entityDetailModel.Value           = item.JulyVal;

                        var detailEntityJuly = entityDetailModel.ToEntity();
                        _ExpenseBudgetService.BMSUnit.ExpenseBudgetDetailRepository.Add(detailEntityJuly);
                        _ExpenseBudgetService.BMSUnit.ExpenseBudgetDetailRepository.SaveChanges();

                        entityDetailModel.ExpenseBudgetId = Convert.ToInt64(Convert.ToInt64(Session["ExpenseBudgetUpdateId"]));
                        entityDetailModel.ParticularId    = item.ParticularId;
                        entityDetailModel.BudgetMonth     = 8;
                        entityDetailModel.Value           = item.AugVal;

                        var detailEntityAugest = entityDetailModel.ToEntity();
                        _ExpenseBudgetService.BMSUnit.ExpenseBudgetDetailRepository.Add(detailEntityAugest);
                        _ExpenseBudgetService.BMSUnit.ExpenseBudgetDetailRepository.SaveChanges();

                        entityDetailModel.ExpenseBudgetId = Convert.ToInt64(Convert.ToInt64(Session["ExpenseBudgetUpdateId"]));
                        entityDetailModel.ParticularId    = item.ParticularId;
                        entityDetailModel.BudgetMonth     = 9;
                        entityDetailModel.Value           = item.SepVal;

                        var detailEntitySeptember = entityDetailModel.ToEntity();
                        _ExpenseBudgetService.BMSUnit.ExpenseBudgetDetailRepository.Add(detailEntitySeptember);
                        _ExpenseBudgetService.BMSUnit.ExpenseBudgetDetailRepository.SaveChanges();

                        entityDetailModel.ExpenseBudgetId = Convert.ToInt64(Convert.ToInt64(Session["ExpenseBudgetUpdateId"]));
                        entityDetailModel.ParticularId    = item.ParticularId;
                        entityDetailModel.BudgetMonth     = 10;
                        entityDetailModel.Value           = item.OctVal;

                        var detailEntityOctober = entityDetailModel.ToEntity();
                        _ExpenseBudgetService.BMSUnit.ExpenseBudgetDetailRepository.Add(detailEntityOctober);
                        _ExpenseBudgetService.BMSUnit.ExpenseBudgetDetailRepository.SaveChanges();

                        entityDetailModel.ExpenseBudgetId = Convert.ToInt64(Convert.ToInt64(Session["ExpenseBudgetUpdateId"]));
                        entityDetailModel.ParticularId    = item.ParticularId;
                        entityDetailModel.BudgetMonth     = 11;
                        entityDetailModel.Value           = item.NovVal;

                        var detailEntityNovember = entityDetailModel.ToEntity();
                        _ExpenseBudgetService.BMSUnit.ExpenseBudgetDetailRepository.Add(detailEntityNovember);
                        _ExpenseBudgetService.BMSUnit.ExpenseBudgetDetailRepository.SaveChanges();

                        entityDetailModel.ExpenseBudgetId = Convert.ToInt64(Convert.ToInt64(Session["ExpenseBudgetUpdateId"]));
                        entityDetailModel.ParticularId    = item.ParticularId;
                        entityDetailModel.BudgetMonth     = 12;
                        entityDetailModel.Value           = item.DecVal;

                        var detailEntityDecember = entityDetailModel.ToEntity();
                        _ExpenseBudgetService.BMSUnit.ExpenseBudgetDetailRepository.Add(detailEntityDecember);
                        _ExpenseBudgetService.BMSUnit.ExpenseBudgetDetailRepository.SaveChanges();


                        //list.Add(entityDetailModel);
                    }
                }

                //Session["lstSampleRequestDetails"] = list;
                //return Json(_SampleRequestModel, JsonRequestBehavior.AllowGet);
                //strMessage = Boolean.TrueString;

                strMessage = "Information has been Updated successfully";
            }
            catch (Exception ex)
            {
                strMessage = CommonExceptionMessage.GetExceptionMessage(ex, CommonAction.Save);
            }

            return(Json(new { strMessage = strMessage }));
        }
Ejemplo n.º 2
0
 public static tblExpenseBudgetDetail ToEntity(this ExpenseBudgetDetail model)
 {
     return(Mapper.Map <ExpenseBudgetDetail, tblExpenseBudgetDetail>(model));
 }