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)); }
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); }
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)); }