public async Task <Manifestinformation> InsertInformation(Manifestinformation obj) { try { if (obj.Id <= 0) { db.Manifestinformation.Add(obj); } else { var existsData = db.Manifestinformation.SingleOrDefault(x => x.Id == obj.Id); if (existsData != null) { db.Entry(existsData).CurrentValues.SetValues(obj); } else { throw new SystemException("Data Not Found !"); } } var result = await db.SaveChangesAsync(); if (result <= 0) { throw new SystemException("Data Not Saved !"); } return(obj); } catch (Exception ex) { throw new SystemException(ex.Message); } }
public async Task <IActionResult> UpdateInformation(Manifestinformation obj) { try { var result = await context.InsertInformation(obj); return(Ok(result)); } catch (Exception ex) { return(BadRequest(new ErrorMessage(ex.Message))); } }
public async Task <bool> UpdateInformation(Manifestinformation obj) { if (obj.Id == 0) { var info = db.Manifestinformation.Where(O => O.ManifestId == obj.ManifestId).FirstOrDefault(); if (info == null) { db.Manifestinformation.Add(obj); } else { db.Entry(obj).CurrentValues.SetValues(obj); } var result = await db.SaveChangesAsync(); if (result <= 0) { throw new SystemException("Data Not Saved !"); } } return(true); }