public IHttpActionResult post([FromBody] uom uoms) { try { if (string.IsNullOrEmpty(uoms.name)) { ModelState.AddModelError("name", "Name is Required"); } if (ModelState.IsValid) { using (Count10_DevEntities entities = new Count10_DevEntities()) { uoms.active = uoms.active.HasValue ? uoms.active : true; uoms.archived = uoms.archived.HasValue ? uoms.archived : false; uoms.updated_by = uoms.updated_by.HasValue ? uoms.updated_by : 1; uoms.created_by = uoms.created_by.HasValue ? uoms.created_by : 1; uoms.created_at = DateTime.Now; uoms.updated_at = DateTime.Now; entities.uoms.Add(uoms); entities.SaveChanges(); var message = Request.CreateResponse(HttpStatusCode.Created, uoms); } return(Ok(uoms)); } return(BadRequest(ModelState)); } catch (Exception) { return(BadRequest(ModelState)); } }
public HttpResponseMessage put(int id, [FromBody] uom uoms) { try { using (Count10_DevEntities entities = new Count10_DevEntities()) { var entity = entities.uoms.FirstOrDefault(e => e.id == id); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "uoms with Id = " + id.ToString() + " not found to edit")); } else { entity.name = uoms.name; entity.alt_name = uoms.alt_name; entity.category = uoms.category; entity.desc = uoms.desc; entity.notes = uoms.notes; entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, entity)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public string saveuom(uom uomobject) { uomclass uomsrc = new uomclass(); string result = string.Empty; if (uomobject.UOMID != 0) { //update var check = getuoms() .Where(c => c.UOMID != uomobject.UOMID) .Where(c => c.UOMName == uomobject.UOMName) .Where(c => c.IsDeleted == false) .FirstOrDefault(); if (check != null) { result = "UOM TAKEN"; } else { var obj = uomsrc.saveuom(uomobject); if (obj != null) { result = "Success"; } } } else { var check = getuoms() .Where(c => c.UOMName == uomobject.UOMName) .Where(c => c.IsDeleted == false) .FirstOrDefault(); if (check != null) { result = "UOM TAKEN"; } else { var obj = uomsrc.saveuom(uomobject); if (obj != null) { result = "Success"; } } } return(result); }