public void Update(User model) { try { bool isNew = false; //if (!IsValid(model)) throw new Exception("Restricciones de modelo"); User modelDB; if (model.id == Guid.Empty) { modelDB = new User(); Audit(modelDB); modelDB.id = UID.CreateUId(model.username); modelDB.username = model.username; modelDB.password = mcga.tools.Cryptog.EncriptarMD5(model.password); db.Users.Add(modelDB); isNew = true; } else { modelDB = db.Users.Find(model.id); if (modelDB == null) { throw new CrudException("Users", CrudAction.Find, model.id); } db.Entry(modelDB).State = EntityState.Modified; } modelDB.firstName = model.firstName; modelDB.lastName = model.lastName; modelDB.email = model.email; modelDB.role = model.role; modelDB.active = model.active; modelDB.bloqued = model.bloqued; Audit(modelDB); db.SaveChanges(); model.id = modelDB.id; } catch (Exception ex) { if (model.id == Guid.Empty) { throw new CrudException("User", CrudAction.Create, ex.Message); } else { throw new CrudException("User", CrudAction.Update, model.id, ex.Message); } } }