private Tuple <bool, string> ValidateColly(colly value) { string message = ""; bool valid = true; if (value.PenjualanId <= 0) { message = "Id Penjualan < 0"; valid = false; } if (value.Weight <= 0) { valid = false; message = "Berat < 0"; } if (value.CollyNumber <= 0) { valid = false; message = "Colly Number 0"; } if (value.TypeOfWeight == TypeOfWeight.None) { valid = false; message = "Type Of Weight Can Not None"; } return(Tuple.Create(valid, message)); }
internal async Task <colly> RemoveItem(colly selectedItem) { using (var client = new Client("Collies")) { return(await client.Delete <colly>("Delete", selectedItem.Id)); } }
// PUT: api/Collies/5 public async Task <IHttpActionResult> Put(int id, colly value) { try { return(Ok(await context.Put(value))); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public Task <colly> Put(colly value) { using (var db = new OcphDbContext()) { Tuple <bool, string> validateResult = ValidateColly(value); if (validateResult.Item1 == true) { value.Id = db.Collies.InsertAndGetLastID(value); if (value.Id > 0) { return(Task.FromResult(value)); } else { throw new SystemException("Data Tidak Tersimpan"); } } else { throw new SystemException(validateResult.Item2); } } }