public BusinessEntities.UserEntity CreateUser(BusinessEntities.UserEntity userEntity) { if (userEntity == null) { return(null); } using (var scope = new TransactionScope()) { var user = Mapper.Map <UserEntity, User>(userEntity); _unitOfWork.UserRepository.Insert(user); _unitOfWork.Save(); scope.Complete(); userEntity.id = user.Id; return(userEntity); } }
/// <summary> /// Creates a User /// </summary> /// <param name="UserEntity"></param> /// <returns></returns> public long CreateUser(UserEntity UserEntity) { using (var scope = new TransactionScope()) { var User = new User { FName = UserEntity.FName, LName = UserEntity.LName, Email = UserEntity.Email, Password = UserEntity.Password }; _unitOfWork.UserRepository.Insert(User); _unitOfWork.Save(); scope.Complete(); return User.Id; } }
public ActionResult Register(UserEntity userData) { if (ModelState.IsValid) { try { long userId = _userServices.CreateUser(userData); if(userId != 0) { return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", "Error occur while creating user!"); } } catch (Exception EX) { ModelState.AddModelError("", "Error occur while creating user!"); } } return View(); }
/// <summary> /// Updates a User /// </summary> /// <param name="UserId"></param> /// <param name="UserEntity"></param> /// <returns></returns> public bool UpdateUser(int UserId, UserEntity UserEntity) { var success = false; if (UserEntity != null) { using (var scope = new TransactionScope()) { var User = _unitOfWork.UserRepository.GetByID(UserId); if (User != null) { User.FName = UserEntity.FName; User.LName = UserEntity.LName; User.Email = UserEntity.Email; User.Password = UserEntity.Password; _unitOfWork.UserRepository.Update(User); _unitOfWork.Save(); scope.Complete(); success = true; } } } return success; }
public ActionResult Register(UserEntity userData) { return RedirectToAction("Index", "Home"); }