public ResultAndError <FamilyProvider> Add(FamilyProvider c) { ResultAndError <FamilyProvider> result = new ResultAndError <FamilyProvider>(); try { db.FamilyProviders.Add(c); db.SaveChanges(); return(result.AddResult(c)); } catch (Exception e) { return(result.AddError(e, HttpStatusCode.InternalServerError)); } }
public bool DeleteMulti(IEnumerable <string> FamilyProviders) { List <FamilyProvider> oFamilyProviders = new List <FamilyProvider>(); foreach (string FamilyProviderNo in FamilyProviders) { FamilyProvider oFamilyProvider = Get(FamilyProviderNo); if (oFamilyProvider != null) { oFamilyProviders.Add(oFamilyProvider); } } db.FamilyProviders.RemoveRange(oFamilyProviders); db.SaveChanges(); return(true); }
public bool UpdateMulti(IEnumerable <FamilyProvider> oFamilyProviders, bool insertIfNoExists = false) { foreach (FamilyProvider FamilyProvider in oFamilyProviders) { FamilyProvider old = Get(FamilyProvider.VendorNo); if (old == null && insertIfNoExists) { Add(FamilyProvider); } else { db.Entry(old).CurrentValues.SetValues(FamilyProvider); } } db.SaveChanges(); return(true); }
public ResultAndError <FamilyProvider> Update(FamilyProvider cr, bool insertIfNoExists = false) { ResultAndError <FamilyProvider> result = new ResultAndError <FamilyProvider>(); try { FamilyProvider old = Get(cr.VendorNo); if (old == null && insertIfNoExists) { return(Add(cr)); } db.Entry(old).CurrentValues.SetValues(cr); db.SaveChanges(); return(result.AddResult(cr)); } catch (Exception e) { return(result.AddError(e, HttpStatusCode.InternalServerError)); } }
public ResultAndError <bool> Delete(string id) { ResultAndError <bool> result = new ResultAndError <bool>(); try { FamilyProvider FamilyProvider = Get(id); if (FamilyProvider == null) { return(result.AddError("No se encontro la tarifa con el id " + id)); } db.FamilyProviders.Remove(FamilyProvider); db.SaveChanges(); return(result.AddResult(true)); } catch (Exception e) { return(result.AddError(e, HttpStatusCode.InternalServerError)); } }
public IActionResult UpdFamilyProvider([FromBody] FamilyProvider familyProvider, bool insertIfNoExists = false) { return(Ok(fBS.Update(familyProvider, insertIfNoExists))); }