Exemplo n.º 1
0
        public ActionResult Create(SalesBudgetModel viewModel)
        {
            var strMessage = string.Empty;

            try
            {
                if (Session["lstSampleRequestDetails"] != null)
                {
                    if (ModelState.IsValid)
                    {
                        #region Current User
                        var userName = HttpContext.User.Identity.Name;
                        viewModel.IUser = userName;
                        viewModel.IDate = DateTime.Now;
                        viewModel.EDate = DateTime.Now;
                        #endregion



                        //List<SalesBudgetDetailViewModel> list = new List<SalesBudgetDetailViewModel>();
                        //if (Session["lstSampleRequestDetails"] != null)
                        //{
                        //    list = (List<SalesBudgetDetailViewModel>)Session["lstSampleRequestDetails"];
                        //}

                        var entity = viewModel.ToEntity();

                        _SalesBudgetService.BMSUnit.SalesBudgetRepository.Add(entity);
                        _SalesBudgetService.BMSUnit.SalesBudgetRepository.SaveChanges();

                        Session["SampleRequestMasterId"] = entity.Id;

                        #region Save SampleRequest Detail

                        //if (list != null && list.Count > 0)
                        //{
                        //    foreach (SampleRequestDetailModel detail in list)
                        //    {

                        //        detail.RequestId = Convert.ToInt64(entity.Id);
                        //        var detailEntity = detail.ToEntity();
                        //        _SalesBudgetService.BMSUnit.SampleRequestDetailsRepository.Add(detailEntity);
                        //        _SalesBudgetService.BMSUnit.SampleRequestDetailsRepository.SaveChanges();
                        //    }
                        //}

                        //Session["lstSampleRequestDetails"] = null;

                        //#endregion

                        //#region Save Sample Request Document

                        //foreach (SampleDocumentModel doc in viewModel.sampleDocumentModels)
                        //{
                        //    if (doc.IsSelected == true)
                        //    {
                        //        SampleRequestDocumentModel aaa = new SampleRequestDocumentModel();
                        //        aaa.RequestId = Convert.ToInt64(entity.Id);
                        //        aaa.DocumentId = doc.Id;
                        //        var detailDocumentEntity = aaa.ToEntity();
                        //        _SalesBudgetService.BMSUnit.SampleRequestDocumentRepository.Add(detailDocumentEntity);
                        //        _SalesBudgetService.BMSUnit.SampleRequestDocumentRepository.SaveChanges();
                        //    }
                        //}

                        #endregion

                        return(Content(Boolean.TrueString));
                    }
                }
                strMessage = Common.GetModelStateErrorMessage(ModelState);
            }
            catch (Exception ex)
            {
                strMessage = CommonExceptionMessage.GetExceptionMessage(ex, CommonAction.Save);
            }

            return(Content(strMessage));
        }
Exemplo n.º 2
0
        public JsonResult SetSalesBudgetForUpdate(List <SalesBudgetModel> lstSampleSubmissionMaster, List <SalesBudgetDetailViewModel> lstSampleSubmissionDetails, string UpdateId)
        {
            var strMessage = string.Empty;

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

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

                    //var lst = _SalesBudgetService.BMSUnit.SalesBudgetRepository.GetAll().Where(
                    //                q => q.Id == model.Id);

                    //foreach (var dt in lst)
                    //{
                    //    _SalesBudgetService.BMSUnit.SalesBudgetRepository.Delete_64Bit(Convert.ToInt64(dt.Id));
                    //}

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

                    foreach (var item in lstSampleSubmissionMaster)
                    {
                        SalesBudgetModel masterEntityModel = new SalesBudgetModel();

                        #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.BudgetYear    = item.BudgetYear;
                        masterEntityModel.ProductId     = item.ProductId;
                        masterEntityModel.SBUId         = item.SBUId;
                        masterEntityModel.Id            = Id;
                        //masterList.Add(masterEntityModel);

                        var entity = masterEntityModel.ToEntity();
                        _SalesBudgetService.BMSUnit.SalesBudgetRepository.Update(entity);
                        _SalesBudgetService.BMSUnit.SalesBudgetRepository.SaveChanges();

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

                    var lst = _SalesBudgetService.BMSUnit.SalesBudgetDetailRepository.GetAll().Where(
                        q => q.SalesBudgetId == Convert.ToInt64(Session["SalesBudgetId"]));

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


                    // Add new detail information

                    foreach (var item in lstSampleSubmissionDetails)
                    {
                        SalesBudgetDetail entityDetailModel = new SalesBudgetDetail();

                        entityDetailModel.SalesBudgetId = Convert.ToInt64(Convert.ToInt64(Session["SalesBudgetId"]));
                        entityDetailModel.CustomerId    = item.CustomerId;
                        entityDetailModel.SupplierId    = item.SupplierId;
                        entityDetailModel.BudgetMonth   = 1;
                        entityDetailModel.Quantity      = item.JanQty;
                        entityDetailModel.Value         = item.JanVal;
                        entityDetailModel.Commission    = item.JanCom;

                        var detailEntityjan = entityDetailModel.ToEntity();
                        _SalesBudgetService.BMSUnit.SalesBudgetDetailRepository.Add(detailEntityjan);
                        _SalesBudgetService.BMSUnit.SalesBudgetDetailRepository.SaveChanges();

                        entityDetailModel.SalesBudgetId = Convert.ToInt64(Convert.ToInt64(Session["SalesBudgetId"]));
                        entityDetailModel.CustomerId    = item.CustomerId;
                        entityDetailModel.SupplierId    = item.SupplierId;
                        entityDetailModel.BudgetMonth   = 2;
                        entityDetailModel.Quantity      = item.FebQty;
                        entityDetailModel.Value         = item.FebVal;
                        entityDetailModel.Commission    = item.FebCom;

                        var detailEntityFeb = entityDetailModel.ToEntity();
                        _SalesBudgetService.BMSUnit.SalesBudgetDetailRepository.Add(detailEntityFeb);
                        _SalesBudgetService.BMSUnit.SalesBudgetDetailRepository.SaveChanges();

                        entityDetailModel.SalesBudgetId = Convert.ToInt64(Convert.ToInt64(Session["SalesBudgetId"]));
                        entityDetailModel.CustomerId    = item.CustomerId;
                        entityDetailModel.SupplierId    = item.SupplierId;
                        entityDetailModel.BudgetMonth   = 3;
                        entityDetailModel.Quantity      = item.MarQty;
                        entityDetailModel.Value         = item.MarVal;
                        entityDetailModel.Commission    = item.MarCom;

                        var detailEntityMarch = entityDetailModel.ToEntity();
                        _SalesBudgetService.BMSUnit.SalesBudgetDetailRepository.Add(detailEntityMarch);
                        _SalesBudgetService.BMSUnit.SalesBudgetDetailRepository.SaveChanges();

                        entityDetailModel.SalesBudgetId = Convert.ToInt64(Convert.ToInt64(Session["SalesBudgetId"]));
                        entityDetailModel.CustomerId    = item.CustomerId;
                        entityDetailModel.SupplierId    = item.SupplierId;
                        entityDetailModel.BudgetMonth   = 4;
                        entityDetailModel.Quantity      = item.AprQty;
                        entityDetailModel.Value         = item.AprVal;
                        entityDetailModel.Commission    = item.AprCom;

                        var detailEntityApril = entityDetailModel.ToEntity();
                        _SalesBudgetService.BMSUnit.SalesBudgetDetailRepository.Add(detailEntityApril);
                        _SalesBudgetService.BMSUnit.SalesBudgetDetailRepository.SaveChanges();

                        entityDetailModel.SalesBudgetId = Convert.ToInt64(Convert.ToInt64(Session["SalesBudgetId"]));
                        entityDetailModel.CustomerId    = item.CustomerId;
                        entityDetailModel.SupplierId    = item.SupplierId;
                        entityDetailModel.BudgetMonth   = 5;
                        entityDetailModel.Quantity      = item.MayQty;
                        entityDetailModel.Value         = item.MayVal;
                        entityDetailModel.Commission    = item.MayCom;

                        var detailEntityMay = entityDetailModel.ToEntity();
                        _SalesBudgetService.BMSUnit.SalesBudgetDetailRepository.Add(detailEntityMay);
                        _SalesBudgetService.BMSUnit.SalesBudgetDetailRepository.SaveChanges();

                        entityDetailModel.SalesBudgetId = Convert.ToInt64(Convert.ToInt64(Session["SalesBudgetId"]));
                        entityDetailModel.CustomerId    = item.CustomerId;
                        entityDetailModel.SupplierId    = item.SupplierId;
                        entityDetailModel.BudgetMonth   = 6;
                        entityDetailModel.Quantity      = item.JunQty;
                        entityDetailModel.Value         = item.JunVal;
                        entityDetailModel.Commission    = item.JunCom;

                        var detailEntityJun = entityDetailModel.ToEntity();
                        _SalesBudgetService.BMSUnit.SalesBudgetDetailRepository.Add(detailEntityJun);
                        _SalesBudgetService.BMSUnit.SalesBudgetDetailRepository.SaveChanges();

                        entityDetailModel.SalesBudgetId = Convert.ToInt64(Convert.ToInt64(Session["SalesBudgetId"]));
                        entityDetailModel.CustomerId    = item.CustomerId;
                        entityDetailModel.SupplierId    = item.SupplierId;
                        entityDetailModel.BudgetMonth   = 7;
                        entityDetailModel.Quantity      = item.JulyQty;
                        entityDetailModel.Value         = item.JulyVal;
                        entityDetailModel.Commission    = item.JulyCom;

                        var detailEntityJuly = entityDetailModel.ToEntity();
                        _SalesBudgetService.BMSUnit.SalesBudgetDetailRepository.Add(detailEntityJuly);
                        _SalesBudgetService.BMSUnit.SalesBudgetDetailRepository.SaveChanges();

                        entityDetailModel.SalesBudgetId = Convert.ToInt64(Convert.ToInt64(Session["SalesBudgetId"]));
                        entityDetailModel.CustomerId    = item.CustomerId;
                        entityDetailModel.SupplierId    = item.SupplierId;
                        entityDetailModel.BudgetMonth   = 8;
                        entityDetailModel.Quantity      = item.AugQty;
                        entityDetailModel.Value         = item.AugVal;
                        entityDetailModel.Commission    = item.AugCom;

                        var detailEntityAugest = entityDetailModel.ToEntity();
                        _SalesBudgetService.BMSUnit.SalesBudgetDetailRepository.Add(detailEntityAugest);
                        _SalesBudgetService.BMSUnit.SalesBudgetDetailRepository.SaveChanges();

                        entityDetailModel.SalesBudgetId = Convert.ToInt64(Convert.ToInt64(Session["SalesBudgetId"]));
                        entityDetailModel.CustomerId    = item.CustomerId;
                        entityDetailModel.SupplierId    = item.SupplierId;
                        entityDetailModel.BudgetMonth   = 9;
                        entityDetailModel.Quantity      = item.SepQty;
                        entityDetailModel.Value         = item.SepVal;
                        entityDetailModel.Commission    = item.SepVal;

                        var detailEntitySeptember = entityDetailModel.ToEntity();
                        _SalesBudgetService.BMSUnit.SalesBudgetDetailRepository.Add(detailEntitySeptember);
                        _SalesBudgetService.BMSUnit.SalesBudgetDetailRepository.SaveChanges();

                        entityDetailModel.SalesBudgetId = Convert.ToInt64(Convert.ToInt64(Session["SalesBudgetId"]));
                        entityDetailModel.CustomerId    = item.CustomerId;
                        entityDetailModel.SupplierId    = item.SupplierId;
                        entityDetailModel.BudgetMonth   = 10;
                        entityDetailModel.Quantity      = item.OctQty;
                        entityDetailModel.Value         = item.OctVal;
                        entityDetailModel.Commission    = item.OctCom;

                        var detailEntityOctober = entityDetailModel.ToEntity();
                        _SalesBudgetService.BMSUnit.SalesBudgetDetailRepository.Add(detailEntityOctober);
                        _SalesBudgetService.BMSUnit.SalesBudgetDetailRepository.SaveChanges();

                        entityDetailModel.SalesBudgetId = Convert.ToInt64(Convert.ToInt64(Session["SalesBudgetId"]));
                        entityDetailModel.CustomerId    = item.CustomerId;
                        entityDetailModel.SupplierId    = item.SupplierId;
                        entityDetailModel.BudgetMonth   = 11;
                        entityDetailModel.Quantity      = item.NovQty;
                        entityDetailModel.Value         = item.NovVal;
                        entityDetailModel.Commission    = item.NovCom;

                        var detailEntityNovember = entityDetailModel.ToEntity();
                        _SalesBudgetService.BMSUnit.SalesBudgetDetailRepository.Add(detailEntityNovember);
                        _SalesBudgetService.BMSUnit.SalesBudgetDetailRepository.SaveChanges();

                        entityDetailModel.SalesBudgetId = Convert.ToInt64(Convert.ToInt64(Session["SalesBudgetId"]));
                        entityDetailModel.CustomerId    = item.CustomerId;
                        entityDetailModel.SupplierId    = item.SupplierId;
                        entityDetailModel.BudgetMonth   = 12;
                        entityDetailModel.Quantity      = item.DecQty;
                        entityDetailModel.Value         = item.DecVal;
                        entityDetailModel.Commission    = item.DecCom;

                        var detailEntityDecember = entityDetailModel.ToEntity();
                        _SalesBudgetService.BMSUnit.SalesBudgetDetailRepository.Add(detailEntityDecember);
                        _SalesBudgetService.BMSUnit.SalesBudgetDetailRepository.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 }));
        }