// GET: /ProductMaster/Create

        public ActionResult Create()
        {
            int DivisionId         = (int)System.Web.HttpContext.Current.Session["DivisionId"];
            ProductInvoiceGroup vm = new ProductInvoiceGroup();

            vm.DivisionId = DivisionId;
            vm.IsActive   = true;
            vm.SeparateWeightInInvoice = false;
            return(View("Create", vm));
        }
        // GET: /ProductMaster/Edit/5

        public ActionResult Edit(int id)
        {
            ProductInvoiceGroup pt = _ProductInvoiceGroupService.Find(id);

            if (pt == null)
            {
                return(HttpNotFound());
            }
            return(View("Create", pt));
        }
        // GET: /ProductMaster/Delete/5

        public ActionResult Delete(int id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProductInvoiceGroup ProductInvoiceGroup = _ProductInvoiceGroupService.Find(id);

            if (ProductInvoiceGroup == null)
            {
                return(HttpNotFound());
            }

            ReasonViewModel vm = new ReasonViewModel()
            {
                id = id,
            };

            return(PartialView("_Reason", vm));
        }
 public ProductInvoiceGroup Add(ProductInvoiceGroup pt)
 {
     _unitOfWork.Repository <ProductInvoiceGroup>().Insert(pt);
     return(pt);
 }
 public void Update(ProductInvoiceGroup pt)
 {
     pt.ObjectState = ObjectState.Modified;
     _unitOfWork.Repository <ProductInvoiceGroup>().Update(pt);
 }
 public void Delete(ProductInvoiceGroup pt)
 {
     _unitOfWork.Repository <ProductInvoiceGroup>().Delete(pt);
 }
 public ProductInvoiceGroup Create(ProductInvoiceGroup pt)
 {
     pt.ObjectState = ObjectState.Added;
     _unitOfWork.Repository <ProductInvoiceGroup>().Insert(pt);
     return(pt);
 }
        public ActionResult Post(ProductInvoiceGroup vm)
        {
            ProductInvoiceGroup pt = vm;

            if (ModelState.IsValid)
            {
                if (vm.ProductInvoiceGroupId <= 0)
                {
                    //pt.DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"];
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _ProductInvoiceGroupService.Create(pt);

                    try
                    {
                        _unitOfWork.Save();
                    }

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

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductInvoiceGroup).DocumentTypeId,
                        DocId        = pt.ProductInvoiceGroupId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));


                    return(RedirectToAction("Create").Success("Data saved successfully"));
                }
                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                    ProductInvoiceGroup temp = _ProductInvoiceGroupService.Find(pt.ProductInvoiceGroupId);

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

                    temp.ProductInvoiceGroupName = pt.ProductInvoiceGroupName;
                    temp.DivisionId              = pt.DivisionId;
                    temp.IsActive                = pt.IsActive;
                    temp.ItcHsCode               = pt.ItcHsCode;
                    temp.Rate                    = pt.Rate;
                    temp.Weight                  = pt.Weight;
                    temp.Knots                   = pt.Knots;
                    temp.DescriptionOfGoodsId    = pt.DescriptionOfGoodsId;
                    temp.IsSample                = pt.IsSample;
                    temp.SeparateWeightInInvoice = pt.SeparateWeightInInvoice;
                    temp.ModifiedDate            = DateTime.Now;
                    temp.ModifiedBy              = User.Identity.Name;
                    temp.ObjectState             = Model.ObjectState.Modified;
                    _ProductInvoiceGroupService.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);
                        return(View("Create", pt));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductInvoiceGroup).DocumentTypeId,
                        DocId           = temp.ProductInvoiceGroupId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index").Success("Data saved successfully"));
                }
            }

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