public IHttpActionResult EFUpdateUser(FarmworkersWebAPI.Entities.User _userInformation) { FarmworkersWebAPI.Entities.User _updated = null; try { if (_userInformation.UserID == 0) { return(Ok("User Wasn't Updated - User ID is Invalid")); } FarmworkersWebAPI.Entities.User original = _context.Users. Where(u => u.UserID.Equals(_userInformation.UserID)).FirstOrDefault(); if (original != null) { _context.Entry(original).CurrentValues.SetValues(_userInformation); _context.SaveChanges(); _updated = _context.Users. Where(u => u.UserID.Equals(_userInformation.UserID)).FirstOrDefault(); return(Ok(AutoMapper.Mapper.Map <UserWithFarmDTO>(_updated))); } } catch (Exception ex) { return(InternalServerError(ex)); } return(Ok("User Wasn't Updated - User Doesn't Exist")); }
public IHttpActionResult EFInsertUser(FarmworkersWebAPI.Entities.User _userInformation) { _context.Configuration.ProxyCreationEnabled = false; FarmworkersWebAPI.Entities.User _userData = new FarmworkersWebAPI.Entities.User(); try { if (EFCheckUserExistsController("UserPhoneNumber", _userInformation.UserPhoneNumber, "Yes").FirstOrDefault() == null || EFCheckUserExistsController("UserEmail", _userInformation.UserEmail, "Yes").FirstOrDefault() == null) { _userData = _context.Users.Add(_userInformation); _context.SaveChanges(); return(Ok(_userData)); } else { return(Ok("User Was NOT Added - User Already Exists")); } } catch (Exception ex) { return(InternalServerError(ex)); } }