public ActionResult Edit(ItemModel model) { Stream req = Request.InputStream; req.Seek(0, SeekOrigin.Begin); string json = new StreamReader(req).ReadToEnd(); var item = _itemRepository.GetById(model.Id); if (ModelState.IsValid) { item = model.ToEntity(item); //always set IsNew to false when saving item.IsNew = false; //update attributes _entityAttributeService.UpdateEntityAttributes(model.Id, EntityType.Item, json); _itemRepository.Update(item); //commit all changes this._dbContext.SaveChanges(); //notification SuccessNotification(_localizationService.GetResource("Record.Saved")); return(new NullJsonResult()); } else { return(Json(new { Errors = ModelState.SerializeErrors() })); } }
public ActionResult Edit(AssetModel model) { Stream req = Request.InputStream; req.Seek(0, SeekOrigin.Begin); string json = new StreamReader(req).ReadToEnd(); var asset = _assetRepository.GetById(model.Id); if (ModelState.IsValid) { //update status history if (model.AssetStatusId != asset.AssetStatusId) { asset.AssetStatusHistories.Add(new AssetStatusHistory { FromStatus = asset.AssetStatus.Name, ToStatus = _valueItemRepository.GetById(model.AssetStatusId).Name, ChangedUserId = this._workContext.CurrentUser.Id, ChangedDateTime = DateTime.UtcNow }); } //update location history if (model.LocationId != asset.LocationId) { asset.AssetLocationHistories.Add(new AssetLocationHistory { FromLocationId = asset.LocationId, ToLocationId = model.LocationId, ChangedUserId = this._workContext.CurrentUser.Id, ChangedDateTime = DateTime.UtcNow }); } asset = model.ToEntity(asset); //always set IsNew to false when saving asset.IsNew = false; //update attributes _entityAttributeService.UpdateEntityAttributes(model.Id, EntityType.Asset, json); _assetRepository.Update(asset); //commit all changes this._dbContext.SaveChanges(); //notification SuccessNotification(_localizationService.GetResource("Record.Saved")); return(new NullJsonResult()); } else { return(Json(new { Errors = ModelState.SerializeErrors() })); } }
public ActionResult Edit(LocationModel model) { Stream req = Request.InputStream; req.Seek(0, SeekOrigin.Begin); string json = new StreamReader(req).ReadToEnd(); var location = _locationRepository.GetById(model.Id); if (ModelState.IsValid) { location = model.ToEntity(location); //set id for Address if (location.AddressId > 0) { location.Address.Id = location.AddressId.Value; } //always set IsNew to false when saving location.IsNew = false; //update attributes _entityAttributeService.UpdateEntityAttributes(model.Id, EntityType.Location, json); _locationRepository.Update(location); //commit all changes this._dbContext.SaveChanges(); //notification SuccessNotification(_localizationService.GetResource("Record.Saved")); return(Json(new { AddressId = location.AddressId })); } else { return(Json(new { Errors = ModelState.SerializeErrors() })); } }