public IHttpActionResult PutProducent(string Code, producent Producent) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (Code != Producent.Code) { return(BadRequest()); } Db.Entry(Producent).State = EntityState.Modified; try { Db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ProducentExists(Code)) { return(NotFound()); } throw; } return(StatusCode(HttpStatusCode.NoContent)); }
private void LoadAdditionalProducentsData(producent Producent) { if (Producent.AddressID != null) { Producent.address = Db.addresses.FirstOrDefault(A => A.ID == Producent.AddressID.Value); } }
public IHttpActionResult GetProducent(string Code) { producent producent = Db.producents.AsEnumerable().FirstOrDefault(X => X.Code == Code); if (producent == null) { return(NotFound()); } LoadAdditionalProducentsData(producent); return(Ok(producent)); }
public IHttpActionResult DeleteProducent(string Code) { producent producent = Db.producents.AsEnumerable().FirstOrDefault(X => X.Code == Code); if (producent == null) { return(NotFound()); } Db.producents.Remove(producent); Db.SaveChanges(); return(Ok(producent)); }
public AddProducentVM(ChangeStatus status, ObservableCollection <producent> source, CollectionView sourceView, producent selectedItem) { this.status = status; this.source = source; this.sourceView = sourceView; this.selectedItem = selectedItem; SaveCommand = new CommandHandler { CanExecuteAction = saveValidation, ExecuteAction = saveAction }; if (status == ChangeStatus.New) { this.Kosongkan(); } else { this.Id = selectedItem.Id; this.Description = selectedItem.Description; this.Name = selectedItem.Name; } }
private void saveAction(object obj) { TopsisLIB.DataCollections.ProducentCollections dataCollection = new TopsisLIB.DataCollections.ProducentCollections(); if (this.status == ChangeStatus.New) { TopsisLIB.Models.producent item = this; var id = dataCollection.Add(item); item.Id = id; if (item.Id > 0) { source.Add(item); sourceView.Refresh(); selectedItem = item; MessageBox.Show("Data Berhasil Disimpan"); } else { MessageBox.Show("Data Gagal Disimpan"); } } else { TopsisLIB.Models.producent item = this; var isUpdated = dataCollection.Update(item); if (isUpdated) { var result = source.Where(O => O.Id == item.Id).FirstOrDefault(); result.Name = item.Name; result.Description = item.Description; sourceView.Refresh(); MessageBox.Show("Data Berhasil Disimpan"); } else { MessageBox.Show("Data Gagal Disimpan"); } } }
public IHttpActionResult PostProducent(producent Producent) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Db.producents.Add(Producent); try { Db.SaveChanges(); } catch (DbUpdateException) { if (ProducentExists(Producent.Code)) { return(Conflict()); } throw; } return(CreatedAtRoute("DefaultApi", new { id = Producent.ID }, Producent)); }