Exemplo n.º 1
0
        public ActionResult _Create(int Id, DateTime?date, bool?IsProdBased)   //Id ==>Sale Order Header Id
        {
            PropertyHeaderViewModel H = _PropertyHeaderService.GetPropertyHeader(Id);
            PropertyLineViewModel   s = new PropertyLineViewModel();

            s.DateOfConsutruction = DateTime.Now.Date;
            s.WEF          = DateTime.Now.Date;
            s.PersonId     = H.PersonID;
            ViewBag.Status = H.Status;

            DiscountType D = _DiscountTypeService.Find("NA");

            s.DiscountTypeId = D.DiscountTypeId;
            s.DiscountRate   = D.Rate;


            PrepareViewBag(s);
            ViewBag.LineMode = "Create";

            return(PartialView("_Create", s));
        }
        public ActionResult Post(DiscountType vm)
        {
            DiscountType pt = vm;

            if (vm.Rate > 100)
            {
                ModelState.AddModelError("Rate", "Rate % value can not be greater then 100.");
            }


            if (ModelState.IsValid)
            {
                if (vm.DiscountTypeId <= 0)
                {
                    pt.Rate         = vm.Rate;
                    pt.IsActive     = true;
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;


                    try
                    {
                        _DiscountTypeService.Create(pt);
                    }



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


                    _logger.LogActivityDetail(logVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = Constants.DocumentTypeIdConstants.DiscountType,
                        DocId        = pt.DiscountTypeId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));


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

                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                    DiscountType temp = _DiscountTypeService.Find(pt.DiscountTypeId);

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

                    temp.Rate             = vm.Rate;
                    temp.DiscountTypeName = pt.DiscountTypeName;
                    temp.IsActive         = pt.IsActive;
                    temp.ModifiedDate     = DateTime.Now;
                    temp.ModifiedBy       = User.Identity.Name;
                    temp.ObjectState      = Model.ObjectState.Modified;


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

                    XElement Modifications = _modificationCheck.CheckChanges(LogList);

                    try
                    {
                        _DiscountTypeService.Update(temp);
                    }

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

                    _logger.LogActivityDetail(logVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = Constants.DocumentTypeIdConstants.DiscountType,
                        DocId           = temp.DiscountTypeId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));

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