public async void LunchRepository_UpdateUserAsync_UpdatesUser() { // arrange LunchContext context = GetContext(); LunchRepository target = new LunchRepository(context); UserEntity user = context.Users.Add(new UserEntity() { Name = "Tahra Dactyl", Nopes = "[]", }).Entity; await context.SaveChangesAsync(); string name = "Paul R. Baer"; List <string> nopes = new List <string> { "Chum Bucket", "Jimmy Pesto's Pizzaria" }; // act await target.UpdateUserAsync(user.Id, name, nopes, "90210"); // assert UserEntity updatedUser = await context.Users.FirstOrDefaultAsync(u => u.Id == user.Id); Assert.Equal(name, updatedUser.Name); Assert.Equal(JsonConvert.SerializeObject(nopes), updatedUser.Nopes); Assert.Equal("90210", updatedUser.Zip); }
public async Task <ActionResult> Create(AddComment addComment /*[Bind(Include = "CommentId,Date,UserId,LunchId,SaladRating,SaladComment,SoupRating,SoupComment,MeatDishRating,MeatDishComment,GarnishRating,GarnishComment")] Comment comment*/) { if (ModelState.IsValid && db.Lunches.Where(l => l.Date == addComment.LunchDate).Count() != 0) { Comment comment = new Comment(); comment.Date = DateTime.Now; comment.UserId = db.Users.Where(u => u.Email == HttpContext.User.Identity.Name).ToList().ElementAt(0).UserId; comment.LunchId = db.Lunches.Where(l => l.Date == addComment.LunchDate).ToList().ElementAt(0).LunchId; comment.SaladRating = addComment.SaladRating; comment.SaladComment = addComment.SaladComment; comment.SoupRating = addComment.SoupRating; comment.SoupComment = addComment.SoupComment; comment.MeatDishRating = addComment.MeatDishRating; comment.MeatDishComment = addComment.MeatDishComment; comment.GarnishRating = addComment.GarnishRating; comment.GarnishComment = addComment.GarnishComment; SetSaladRating(comment); SetSoupRating(comment); SetMeatDishRating(comment); SetGarnishRating(comment); db.Comments.Add(comment); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View()); }
public async Task <bool> UpdateOrderStatus(int orderId, string stauts) { var order = await _dbContext.Orders.FirstOrDefaultAsync(x => x.Id == orderId); if (order == null) { return(false); } order.Status = stauts; return(await _dbContext.SaveChangesAsync() > 0); }
public async Task <ActionResult> Order([Bind(/*Exclude ="Lunch", */ Include = "Lunch, WithoutSoup, IsOrder")] List <OrderViewModel> list) { var currentUser = db.Users.Where(u => u.Email == HttpContext.User.Identity.Name).ToList().ElementAt(0); foreach (OrderViewModel ovm in list) { if (ovm.IsOrder == true) { Order order = new Order(); order.UserId = currentUser.UserId; order.LunchId = ovm.Lunch.LunchId; if (ovm.WithoutSoup == true) { order.WithoutSoup = true; } db.Orders.Add(order); await db.SaveChangesAsync(); } db.SaveChanges(); } return(RedirectToAction("MyOrders")); }
public async void LunchRepository_GetTeamAsync_ReturnsSpecifiedTeam() { // arrange LunchContext context = GetContext(); LunchRepository target = new LunchRepository(context); TeamEntity team = context.Teams.Add(new TeamEntity() { Name = "Tahra Dactyls", Zip = "90210", }).Entity; await context.SaveChangesAsync(); // act TeamDto result = await target.GetTeamAsync(team.Id); // assert Assert.Equal(team.Name, result.Name); Assert.Equal(team.Zip, result.Zip); }
public async void LunchRepository_GetUserAsync_ReturnsSpecifiedUser() { // arrange LunchContext context = GetContext(); LunchRepository target = new LunchRepository(context); UserEntity user = context.Users.Add(new UserEntity() { Name = "Tahra Dactyl", Nopes = "[]", }).Entity; await context.SaveChangesAsync(); // act UserDto result = await target.GetUserAsync(user.Id); // assert Assert.Equal(user.Name, result.Name); Assert.Equal(user.Nopes, JsonConvert.SerializeObject(result.Nopes)); }
public async Task <ActionResult> Activate(AccountActivateViewModel model) { var user = await LunchContext.Users.SingleOrDefaultAsync(u => u.PasswordChangeSecret == model.PasswordChangeSecret); if (user == null) { return(this.View("ActivateSecretInvalid")); } user.Password = HashHelper.GetHash(model.Password); user.PasswordChangeSecret = null; await LunchContext.SaveChangesAsync(); this.LogInInternal(user.EmailAddress); return(this.RedirectToAction("Index", "Home")); }
public async Task <ActionResult> Register(AccountLoginOrRegisterViewModel model) { var loginTaken = await LunchContext.Users.AnyAsync(u => u.EmailAddress == model.Username); if (loginTaken) { ModelState.AddModelError(string.Empty, WebCommon.LoginAlreadyTaken); } else { try { var user = LunchContext.Users.Add(new User { EmailAddress = model.Username, PasswordChangeSecret = Guid.NewGuid() }); var activationUrl = string.Format( "To activate your lunchdictator account please click <a href='{0}{1}'>here</a>", HttpContext.Request.Url.GetCurrentUrl(), Url.Action("Activate", "Account", new { passwordChangeSecret = user.PasswordChangeSecret })); await EmailSender.SendEmail(model.Username, WebCommon.ActivationEmailSubject, activationUrl); await LunchContext.SaveChangesAsync(); model.Message = WebCommon.RegistrationSuccess; } catch (DbEntityValidationException ex) { foreach (var validationError in ex.EntityValidationErrors.Where(v => !v.IsValid)) { foreach (var error in validationError.ValidationErrors) { ModelState.AddModelError(string.Empty, error.ErrorMessage); } } } } return(this.View("LoginOrRegister", model)); }
public async Task <ActionResult> GiveBalance(AddBalanceToUser addBalanceToUser) { var currentUser = db.Users.Where(u => u.Email == HttpContext.User.Identity.Name).ToList().ElementAt(0); if (ModelState.IsValid && addBalanceToUser.AddBalance <= currentUser.Balance && addBalanceToUser.AddBalance > 0) { User user = await db.Users.FindAsync(addBalanceToUser.UserId); if (user == null) { return(HttpNotFound()); } Balance balance = new Balance(); Balance currentBalance = new Balance(); user.Balance += addBalanceToUser.AddBalance; currentUser.Balance -= addBalanceToUser.AddBalance; balance.Date = DateTime.Now; balance.UserId = user.UserId; balance.Income = addBalanceToUser.AddBalance; balance.Comment = "С вами поделился балансом " + currentUser.Name + " " + currentUser.LastName + " (" + currentUser.Email + ")"; db.Balances.Add(balance); currentBalance.Date = DateTime.Now; currentBalance.UserId = currentUser.UserId; currentBalance.Expence = addBalanceToUser.AddBalance; currentBalance.Comment = "Вы поделились балансом с " + user.Name + " " + user.LastName + " (" + user.Email + ")"; db.Balances.Add(currentBalance); db.Entry(user).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("UsersList")); } return(RedirectToAction("GiveBalance", new { id = addBalanceToUser.UserId })); }