public ActionResult SubInv_Update([DataSourceRequest] DataSourceRequest request, SubInvModel model) { if (model != null && ModelState.IsValid) { //productService.Update(model); SubInventory subinv = Mappings.ToEntity(model); subinv.ObjectState = ObjectState.Modified; subinv.ModifiedBy = "I-ALI"; subinv.ModifiedDate = DateTime.Now; _subInventoryService.Update(subinv); try { _unitOfWorkAsync.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ItemExists(model.SubInvCode)) { throw new Exception("Item does not exist."); } throw; } } return(Json(new[] { model }.ToDataSourceResult(request, ModelState))); }
// POST: odata/subinventory public async Task <IHttpActionResult> Post(SubInventory subinventory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } subinventory.ObjectState = ObjectState.Added; _subInventoryService.Insert(subinventory); try { await _unitOfWorkAsync.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ItemExists(subinventory.SubInvCode)) { return(Conflict()); } throw; } return(Created(subinventory)); }
// PUT: odata/subinventory(5) public async Task <IHttpActionResult> Put(string key, SubInventory subinventory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (key != subinventory.SubInvCode) { return(BadRequest()); } subinventory.ObjectState = ObjectState.Modified; _subInventoryService.Update(subinventory); try { await _unitOfWorkAsync.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ItemExists(key)) { return(NotFound()); } throw; } return(Updated(subinventory)); }
// DELETE: odata/subinventory(5) public async Task <IHttpActionResult> Delete(string key) { SubInventory subinventory = await _subInventoryService.FindAsync(key); if (subinventory == null) { return(NotFound()); } subinventory.ObjectState = ObjectState.Deleted; _subInventoryService.Delete(subinventory); await _unitOfWorkAsync.SaveChangesAsync(); return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult SubInv_Destroy([DataSourceRequest] DataSourceRequest request, SubInvModel model) { if (model != null) { //productService.Destroy(model); SubInventory subinv = _subInventoryService.Find(model.SubInvCode); if (subinv == null) { throw new Exception("Item does not exist."); } subinv.ObjectState = ObjectState.Deleted; _subInventoryService.Delete(subinv); _unitOfWorkAsync.SaveChanges(); } return(Json(new[] { model }.ToDataSourceResult(request, ModelState))); }
public static SubInventoryModel ToModel(this SubInventory entity) { return(Mapper.Map <SubInventory, SubInventoryModel>(entity)); }