public async Task <IActionResult> UpdateAuction([FromForm] Publication auction) { if (auction.Id == 0 || auction.price == 0) { return(BadRequest()); } var publication = await _context.Publication.FindAsync(auction.Id); publication.price = auction.price; publication.Description = auction.Description; _context.Entry(publication).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (Exception ex) { string x = ex.Message; throw; } return(NoContent()); }
public void SaveOrUpdateEntitiesList(IList <T> pLstObjEntity) { if (pLstObjEntity != null && pLstObjEntity.Count > 0) { foreach (var lObjEntity in pLstObjEntity) { if (lObjEntity.Id == 0) { lObjEntity.CreationDate = lObjEntity.CreationDate != DateTime.MinValue ? lObjEntity.CreationDate : DateTime.Now; lObjEntity.ModificationDate = lObjEntity.ModificationDate != DateTime.MinValue ? lObjEntity.ModificationDate : DateTime.Now; lObjEntity.Active = true; mLstObjSet.AddObject(lObjEntity); SaveChanges(); SaveChange(ChangeTypeEnum.INSERT, lObjEntity); SaveChanges(); } else { T lObjCurrentEntity = GetEntity(lObjEntity.Id); if (lObjCurrentEntity != null) { if (lObjCurrentEntity.Protected == false) { lObjEntity.CreationDate = lObjCurrentEntity.CreationDate; lObjEntity.ModificationDate = lObjEntity.ModificationDate != DateTime.MinValue ? lObjEntity.ModificationDate : DateTime.Now; lObjEntity.Active = true; mObjContext.Entry(lObjCurrentEntity).CurrentValues.SetValues(lObjEntity); SaveChanges(); SaveChange(ChangeTypeEnum.UPDATE, lObjEntity); SaveChanges(); } else { throw new Exception("Registro protegido contra escritura."); } } } } } }