Exemplo n.º 1
0
        public ItemMaterialDto Update(ItemMaterialDto model)
        {
            if (string.IsNullOrEmpty(model.Name))
            {
                throw new ArgumentException("material name is not allowed to be empty");
            }
            int count  = _repo.GetAll <ItemQuote>().Where(p => p.ItemMaterialId == model.Id).Count();
            var entity = _repo.GetById <ItemMaterial>(model.Id);

            if (count == 0)
            {
                entity = Mapper.Map(model, entity);
                _unitOfWork.RegisterDirty(entity);
            }
            else
            {
                if (model.Sum < entity.Sum)
                {
                    entity.IsEnabled = false;
                    _unitOfWork.RegisterDirty(entity);
                    model.Id = -1;
                    _unitOfWork.RegisterNew(model);
                }
                else
                {
                    entity = Mapper.Map(model, entity);
                    _unitOfWork.RegisterDirty(entity);
                }
            }
            _unitOfWork.Commit();
            return(model);
        }
Exemplo n.º 2
0
        public ItemMaterialDto Add(ItemMaterialDto model)
        {
            if (string.IsNullOrEmpty(model.Name))
            {
                throw new ArgumentException("material name is not allowed to be empty");
            }

            var entity = Mapper.Map <ItemMaterialDto, ItemMaterial>(model);

            //使用UnitOfWork方式
            _unitOfWork.RegisterNew(entity);
            _unitOfWork.Commit();
            return(model);
        }
Exemplo n.º 3
0
        public ActionResult EditMaterial(ItemMaterialDto entity)
        {
            var item = _itemService.Get(entity.ItemID);

            if (entity.Id == -1)
            {
                if (item.IsNotice)
                {
                    item.IsNotice = false;
                    item.IsUpdate = true;
                    _itemService.Update(item);
                }
                entity.IsEnabled = true;
                _itemMaterialService.Add(entity);
                return(Json(new { code = 200, message = "添加成功!" }));
            }
            _itemMaterialService.Update(entity);
            item.IsNotice = false;
            item.IsUpdate = true;
            _itemService.Update(item);
            return(Json(new { code = 200, message = "修改成功!" }));
        }