Esempio n. 1
0
 public void Update(RateListHistory s)
 {
     s.ObjectState = ObjectState.Modified;
     _unitOfWork.Repository <RateListHistory>().Update(s);
 }
Esempio n. 2
0
 public RateListHistory Create(RateListHistory s)
 {
     s.ObjectState = ObjectState.Added;
     _unitOfWork.Repository <RateListHistory>().Insert(s);
     return(s);
 }
Esempio n. 3
0
 public void Delete(RateListHistory s)
 {
     _unitOfWork.Repository <RateListHistory>().Delete(s);
 }
        public ActionResult Post(RateListViewModel vm)
        {
            RateList s = AutoMapper.Mapper.Map <RateListViewModel, RateList>(vm);


            if (ModelState.IsValid)
            {
                if (!vm.RateListId.HasValue || vm.RateListId.Value == 0)
                {
                    s.DocId        = vm.ProductGroupId;
                    s.DealUnitId   = UnitConstants.SqYard;
                    s.CreatedDate  = DateTime.Now;
                    s.ModifiedDate = DateTime.Now;
                    s.CreatedBy    = User.Identity.Name;
                    s.ModifiedBy   = User.Identity.Name;
                    s.ObjectState  = Model.ObjectState.Added;
                    _RateListService.Create(s);


                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        PrepareViewBag();
                        return(View("Create", vm));
                    }



                    return(RedirectToAction("Index").Success("Data saved successfully"));
                }
                else
                {
                    RateList tempRateList = _RateListService.Find(s.RateListId);

                    if (tempRateList.WEF > s.WEF)
                    {
                        ModelState.AddModelError("WEF", "Date cannot be older.");
                        return(View("Create", vm));
                    }

                    RateListHistory History = new RateListHistory();
                    History              = AutoMapper.Mapper.Map <RateList, RateListHistory>(tempRateList);
                    History.ObjectState  = Model.ObjectState.Added;
                    History.CreatedBy    = User.Identity.Name;
                    History.CreatedDate  = DateTime.Now;
                    History.ModifiedBy   = User.Identity.Name;
                    History.ModifiedDate = DateTime.Now;
                    new RateListHistoryService(_unitOfWork).Create(History);


                    tempRateList.Rate         = s.Rate;
                    tempRateList.WEF          = s.WEF;
                    tempRateList.Loss         = s.Loss;
                    tempRateList.UnCountedQty = s.UnCountedQty;
                    tempRateList.ModifiedDate = DateTime.Now;
                    tempRateList.ModifiedBy   = User.Identity.Name;
                    tempRateList.ObjectState  = Model.ObjectState.Modified;
                    _RateListService.Update(tempRateList);


                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        PrepareViewBag();
                        return(View("Create", vm));
                    }

                    return(RedirectToAction("Index").Success("Data saved successfully"));
                }
            }
            return(View("Create", vm));
        }