public int AddUser(ApiUser user) { if (user == null) { throw new ArgumentNullException("user"); } var entityUser = user.ToEntity(); using (rebtelEntities container = new rebtelEntities()) { container.Users.Add(entityUser); container.SaveChanges(); return entityUser.Id; } }
public int AddUser(ApiUser user) { if (user == null) { throw new ArgumentNullException("user"); } var entityUser = user.ToEntity(); using (serviceEntities container = new serviceEntities()) { //If I where to use url-friendly-name I would have done this or maybe have a unique contstraint on the colmn and then add the count in the catch: //int count = container.Users.Where(u => u.FirstName == entityUser.FirstName && u.LastName == entityUser.LastName).Count(); //entityUser.urlFriendly = Utilities.toUrlFriendlyIndentifier(entityUser.FirstName + "-" + entityUser.LastName); //entityUser.urlFriendly += count > 0 ? count.ToString() : ""; container.Users.Add(entityUser); container.SaveChanges(); return entityUser.Id; } }
public ApiUser UpdateUser(ApiUser userValues) { using (rebtelEntities container = new rebtelEntities()) { var user = container.Users.Find(userValues.Id); if (user == null) { throw new FaultException("No such user to update"); } user.FirstName = userValues.FirstName; user.LastName = userValues.LastName; user.Email = userValues.Email; container.SaveChanges(); return new ApiUser(user); } }