Пример #1
0
        public ActionResult Edit(BoxCreateDTO req)
        {
            Response res = new Response();

            if (ModelState.IsValid)
            {
                try
                {
                    if (req.Id > 0)
                    {
                        res.Data = _boxRepository.Update(req);
                    }
                    else
                    {
                        res.Data = _boxRepository.Create(req);
                    }
                }
                catch (Exception ex)
                {
                    res.Message = ex.Message;
                }
            }
            else
            {
                res.Data    = false;
                res.Message = string.Join(",", ModelState
                                          .SelectMany(ms => ms.Value.Errors)
                                          .Select(e => e.ErrorMessage));
            }
            return(Json(res, JsonRequestBehavior.AllowGet));
        }
Пример #2
0
        public async Task <ResultEntity> AddOrUpdateAsync(Box box)
        {
            var result = new ResultEntity();
            var exist  = await _boxRepository.GetQueryable().Where(a => a.FrontBn == box.FrontBn && a.PlaceId == box.PlaceId && a.Id != box.Id).CountAsync() > 0;

            if (exist)
            {
                result.Message = "同一交换场所下BN号码不允许重复";
            }
            else
            {
                if (box.Id > 0)
                {
                    _boxRepository.Update(box);
                }
                else
                {
                    await _boxRepository.AddAsync(box);
                }

                result.Success = true;
            }

            return(result);
        }
Пример #3
0
        public IHttpActionResult PutBox(int id, BoxesModel box)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Box dbBox = _boxRepository.GetFirstOrDefault(b => b.PawzeUser.UserName == User.Identity.Name && b.BoxId == id);

            if (id != box.BoxId)
            {
                return(BadRequest());
            }

            dbBox.Update(box);

            _boxRepository.Update(dbBox);

            try
            {
                _unitOfWork.Commit();
            }
            catch (Exception)
            {
                if (!BoxExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }