public void Update(CarpetSkuSettings s)
 {
     s.ObjectState = ObjectState.Modified;
     _unitOfWork.Repository <CarpetSkuSettings>().Update(s);
 }
 public CarpetSkuSettings Create(CarpetSkuSettings s)
 {
     s.ObjectState = ObjectState.Added;
     _unitOfWork.Repository <CarpetSkuSettings>().Insert(s);
     return(s);
 }
 public void Delete(CarpetSkuSettings s)
 {
     _unitOfWork.Repository <CarpetSkuSettings>().Delete(s);
 }
        public ActionResult Post(CarpetSkuSettingsViewModel vm)
        {
            CarpetSkuSettings pt = AutoMapper.Mapper.Map<CarpetSkuSettingsViewModel, CarpetSkuSettings>(vm);


            if (ModelState.IsValid)
            {

                if (vm.CarpetSkuSettingsId <= 0)
                {
                    pt.CreatedDate = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy = User.Identity.Name;
                    pt.ModifiedBy = User.Identity.Name;
                    pt.ObjectState = Model.ObjectState.Added;
                    _CarpetSkuSettingsService.Create(pt);

                    try
                    {
                        _unitOfWork.Save();
                    }

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

                    int DocTypeId = new DocumentTypeService(_unitOfWork).Find(MasterDocTypeConstants.Carpet).DocumentTypeId;

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocId = pt.CarpetSkuSettingsId,
                        DocTypeId = DocTypeId,
                        ActivityType = (int)ActivityTypeContants.SettingsAdded,
                    }));



                    return RedirectToAction("Index", "CarpetMaster", new { id = 0 }).Success("Data saved successfully");
                }
                else
                {
                    List<LogTypeViewModel> LogList = new List<LogTypeViewModel>();

                    CarpetSkuSettings temp = _CarpetSkuSettingsService.Find(pt.CarpetSkuSettingsId);

                    CarpetSkuSettings ExRec = Mapper.Map<CarpetSkuSettings>(temp);

                    temp.isVisibleProductDesign = vm.isVisibleProductDesign;
                    temp.isVisibleProductStyle = vm.isVisibleProductStyle;
                    temp.isVisibleProductManufacturer = vm.isVisibleProductManufacturer;
                    temp.isVisibleProductDesignPattern = vm.isVisibleProductDesignPattern;
                    temp.isVisibleContent = vm.isVisibleContent;
                    temp.isVisibleOriginCountry = vm.isVisibleOriginCountry;
                    temp.isVisibleInvoiceGroup = vm.isVisibleInvoiceGroup;
                    temp.isVisibleDrawbackTarrif = vm.isVisibleDrawbackTarrif;
                    temp.isVisibleStandardCost = vm.isVisibleStandardCost;
                    temp.isVisibleStandardWeight = vm.isVisibleStandardWeight;
                    temp.isVisibleGrossWeight = vm.isVisibleGrossWeight;
                    temp.isVisibleSupplierDetail = vm.isVisibleSupplierDetail;
                    temp.isVisibleSample = vm.isVisibleSample;
                    temp.isVisibleCounterNo = vm.isVisibleCounterNo;
                    temp.isVisibleTags = vm.isVisibleTags;
                    temp.isVisibleDivision = vm.isVisibleDivision;
                    temp.isVisibleColour = vm.isVisibleColour;
                    temp.isVisibleProductionRemark = vm.isVisibleProductionRemark;
                    temp.ProductDesignId = pt.ProductDesignId;
                    temp.OriginCountryId = pt.OriginCountryId;
                    temp.UnitConversions = pt.UnitConversions;
                    temp.PerimeterSizeTypeId = pt.PerimeterSizeTypeId;
                    temp.isVisibleCBM = pt.isVisibleCBM;
                    temp.isVisibleMapScale = pt.isVisibleMapScale;
                    temp.isVisibleTraceType = pt.isVisibleTraceType;
                    temp.isVisibleMapType = pt.isVisibleMapType;
                    temp.isVisibleStencilSize = pt.isVisibleStencilSize;
                    temp.isVisibleSalesTaxProductCode = pt.isVisibleSalesTaxProductCode;
                    temp.SalesTaxProductCodeCaption = pt.SalesTaxProductCodeCaption;
                    temp.ModifiedDate = DateTime.Now;
                    temp.ModifiedBy = User.Identity.Name;
                    temp.ObjectState = Model.ObjectState.Modified;
                    _CarpetSkuSettingsService.Update(temp);

                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = ExRec,
                        Obj = temp,
                    });

                    XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);

                    try
                    {
                        _unitOfWork.Save();
                    }

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

                    int DocTypeId = new DocumentTypeService(_unitOfWork).Find(MasterDocTypeConstants.Carpet).DocumentTypeId;

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocId = temp.CarpetSkuSettingsId,
                        ActivityType = (int)ActivityTypeContants.SettingsModified,
                        DocTypeId = DocTypeId,
                        xEModifications = Modifications,
                    }));

                    return RedirectToAction("Index", "CarpetMaster", new { id = 0 }).Success("Data saved successfully");

                }

            }
            PrepareViewBag(vm);
            return View("Create", vm);
        }