public IHttpResponse Register(IHttpRequest request, RegisterUserViewModel model) { if (CoreValidator.CheckForMissingKeys(request, FormUserNameKey, FormFullNameKey, FormPasswordKey, FormConfirmPasswordKey)) { return(new BadRequestResponse()); } if (CoreValidator.CheckIfNullOrEmpty(model.Username, model.FullName, model.Password, model.ConfirmPassword)) { return(this.ReturnResponseWithErrorMessage(EmptyFields, UserRegister)); } if (model.Password != model.ConfirmPassword) { return(this.ReturnResponseWithErrorMessage("Pasword and Confirm Password does not match.", UserRegister)); } if (this.unitOfWork.UserRepository.FindByUsername(model.Username) != null) { return(this.ReturnResponseWithErrorMessage("Username already exists.", UserRegister)); } User user = this.unitOfWork .UserRepository .Create(model.Username, model.FullName, model.Password); this.unitOfWork.UserRepository.Add(user); this.unitOfWork.Save(); request.Session.Add(CurrentUserSessionKey, model.Username); request.Session.Add(ShoppingCart.SessionKey, new ShoppingCart()); return(new RedirectResponse("/")); }
public IHttpResponse Add(IHttpRequest request, CreateCakeViewModel model) { const string formNameKey = "name"; const string formPriceKey = "price"; const string formPictureKey = "picture"; if (CoreValidator.CheckForMissingKeys(request, formNameKey, formPriceKey, formPictureKey)) { return(new BadRequestResponse()); } if (CoreValidator.CheckIfNullOrEmpty(model.Name, model.Price.ToString(), model.PictureUrl)) { return(this.ReturnResponseWithErrorMessage(EmptyFields, CakeAdd)); } Product product = this.unitOfWork .ProductRepository .Create(model.Name, model.Price, model.PictureUrl); this.unitOfWork.ProductRepository.Add(product); this.unitOfWork.Save(); this.ViewData["name"] = model.Name; this.ViewData["price"] = model.Price.ToString();; this.ViewData[Key.Result] = Value.Block; return(this.FileViewResponse(CakeAdd)); }
public IHttpResponse Login(IHttpRequest request, LoginUserViewModel model) { if (CoreValidator.CheckForMissingKeys(request, FormUserNameKey, FormPasswordKey)) { return(new BadRequestResponse()); } if (CoreValidator.CheckIfNullOrEmpty(model.Username, model.Password)) { return(this.ReturnResponseWithErrorMessage(EmptyFields, UserLogin)); } User currentUser = this.unitOfWork .UserRepository .FindByUsername(model.Username); if (currentUser == null || currentUser.Password != model.Password) { return(this.ReturnResponseWithErrorMessage("User does not exist. Register a new user.", UserLogin)); } request.Session.Add(CurrentUserSessionKey, model.Username); request.Session.Add(ShoppingCart.SessionKey, new ShoppingCart()); return(new RedirectResponse("/")); }