Пример #1
0
        public void DeleteSize(long sizeId)
        {
            var size = _sizeService.Find(sizeId);

            if (size == null)
            {
                throw new NotFoundException(ErrorCodes.SizeNotFound);
            }
            if (_itemSizeService.Query(x => x.SizeId == sizeId && !x.Item.IsDeleted).Select().Any())
            {
                throw new ValidationException(ErrorCodes.SizeHasItems);
            }
            size.IsDeleted = true;
            _sizeService.Update(size);
            SaveChanges();
        }
Пример #2
0
        public ActionResult Post(Size ptt)
        {
            Size pt = ptt;

            if (ptt.Area == 0)
            {
                PrepareViewBag();
                string message = "Area field is required";
                ModelState.AddModelError("", message);
                ViewBag.Mode = "Add";
                return(View("Create", ptt));
            }

            if (ptt.Perimeter == 0)
            {
                PrepareViewBag();
                string message = "Perimeter field is required";
                ModelState.AddModelError("", message);
                ViewBag.Mode = "Add";
                return(View("Create", ptt));
            }

            if (ModelState.IsValid)
            {
                if (ptt.SizeId <= 0)
                {
                    ptt.CreatedDate  = DateTime.Now;
                    ptt.ModifiedDate = DateTime.Now;
                    ptt.CreatedBy    = User.Identity.Name;
                    ptt.ModifiedBy   = User.Identity.Name;
                    ptt.ObjectState  = Model.ObjectState.Added;
                    var createdSize = _SizeService.Add(ptt);

                    try
                    {
                        _unitOfWork.Save();
                    }

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

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


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

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

                    Size temp = _SizeService.Find(pt.SizeId);

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

                    temp.SizeName       = pt.SizeName;
                    temp.ProductShapeId = pt.ProductShapeId;
                    temp.UnitId         = pt.UnitId;
                    temp.DocTypeId      = pt.DocTypeId;
                    temp.Length         = pt.Length;
                    temp.LengthFraction = pt.LengthFraction;
                    temp.Width          = pt.Width;
                    temp.WidthFraction  = pt.WidthFraction;
                    temp.Height         = pt.Height;
                    temp.HeightFraction = pt.HeightFraction;
                    temp.Area           = pt.Area;
                    temp.Perimeter      = pt.Perimeter;
                    temp.IsActive       = pt.IsActive;
                    temp.ModifiedDate   = DateTime.Now;
                    temp.ModifiedBy     = User.Identity.Name;
                    temp.ObjectState    = Model.ObjectState.Modified;
                    _SizeService.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);
                        ViewBag.Mode = "Edit";
                        return(View("Create", pt));
                    }

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

                    return(RedirectToAction("Index").Success("Data saved successfully"));
                }
            }
            PrepareViewBag();
            ViewBag.Mode = "Add";
            return(View(ptt));
        }