public bool Update(UserViewModel item) { int index = _users.FindIndex(p => p.UserID == item.UserID); if (index == -1) { return false; } _users.RemoveAt(index); _users.Add(item); return true; }
public void Create(UserViewModel user) { if (ModelState.IsValid) { User item = new User { // UserID', 'FirsName', 'LastName', 'Gender', 'Telephone', 'Mail', 'Birthday' UserID = user.UserID, FirstName = user.FirstName.Trim(), LastName = user.LastName, Telephone = user.Telephone, Mail = user.Mail.Trim(), Birthday = user.Birthday, }; _db.User.Add(item); _db.SaveChanges(); } }
public void Edit(UserViewModel user) { if (ModelState.IsValid) { User item = new User { UserID = user.UserID, FirstName = user.FirstName.Trim(), LastName = user.LastName, Telephone = user.Telephone, Mail = user.Mail.Trim(), Birthday = user.Birthday, }; _db.Entry(item).State = EntityState.Modified; _db.SaveChanges(); } }
public void PutProduct(int id, UserViewModel item) { item.UserID = id; if (!repository.Update(item)) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)); } _db.SaveChanges(); }
public UserViewModel Add(UserViewModel item) { item.UserID = _nextId++; _users.Add(item); return item; }