//convert one UnitsOfMeasurement to UnitsOfMeasurementDto public static UnitsOfMeasurementDto convert(UnitsOfMeasurement unitsOfMeasurement) { UnitsOfMeasurementDto NewUnitsOfMeasurement = new UnitsOfMeasurementDto(); NewUnitsOfMeasurement.id = unitsOfMeasurement.id; NewUnitsOfMeasurement.unitName = unitsOfMeasurement.unitName; NewUnitsOfMeasurement.ratioToGram = unitsOfMeasurement.ratioToGram; return(NewUnitsOfMeasurement); }
// DELETE api/<controller>/5 public IHttpActionResult Delete(UnitsOfMeasurementDto value) { if (value == null) { return(BadRequest("לא נשלח מידע")); } value = service.RemoveUnitsOfMeasurement(value); if (value == null) { return(BadRequest("מחיקה נכשלה")); } return(Ok(value)); }
//remove UnitsOfMeasurement from database public UnitsOfMeasurementDto RemoveUnitsOfMeasurement(UnitsOfMeasurementDto unitsOfMeasurementDto) { using (HealthyMenuEntities db = new HealthyMenuEntities()) { try { UnitsOfMeasurement unitsOfMeasurement = db.UnitsOfMeasurements.Remove(Convertion.UnitsOfMeasurementConvertion.convert(unitsOfMeasurementDto)); db.SaveChanges(); return(Convertion.UnitsOfMeasurementConvertion.convert(unitsOfMeasurement)); } catch { return(null); } } }
//update UnitsOfMeasurement in database public UnitsOfMeasurementDto PutUnitsOfMeasurement(UnitsOfMeasurementDto unitsOfMeasurementDto) { using (HealthyMenuEntities db = new HealthyMenuEntities()) { try { UnitsOfMeasurement unitsOfMeasurement = db.UnitsOfMeasurements.FirstOrDefault(x => x.id == unitsOfMeasurementDto.id); if (unitsOfMeasurement == null) { return(null); } unitsOfMeasurement.id = unitsOfMeasurementDto.id; unitsOfMeasurement.unitName = unitsOfMeasurementDto.unitName; unitsOfMeasurement.ratioToGram = unitsOfMeasurementDto.ratioToGram; return(Convertion.UnitsOfMeasurementConvertion.convert(unitsOfMeasurement)); } catch { return(null); } } }