public void Create(AuctionModel auctionModel, HttpServerUtilityBase server, string currentUserId) { _context.Auctions.Add(new Auction { Id = auctionModel.Id, Name = auctionModel.Name, Comments = auctionModel.Comments, Price = auctionModel.Price, ImagePath = ImagemHelper.Save(ImageType.Productos, server, auctionModel.ImageFile), UserId = currentUserId, BestBid = auctionModel.BestBid, Active = true, InitialDate = auctionModel.InitialDate, FinalDate = auctionModel.FinalDate }); _context.SaveChanges(); }
public void Update(AuctionModel auctionModel, HttpServerUtilityBase server, string currentUserId) { var auction = _context.Auctions.ToList().Where(a => a.Id == auctionModel.Id).FirstOrDefault(); auction.Name = auctionModel.Name; auction.Price = auctionModel.Price; auction.UserId = currentUserId; auction.InitialDate = auctionModel.InitialDate; auction.FinalDate = auctionModel.FinalDate; auction.Comments = auctionModel.Comments; auction.BestBid = auctionModel.BestBid; auction.Active = auctionModel.Active; auction.ImagePath = ImagemHelper.Save(ImageType.Productos, server, auctionModel.ImageFile); _context.Entry(auction).State = EntityState.Modified; _context.SaveChanges(); }
public async Task <ActionResult> ChangeImageUser(ChangeImageUserViewModel model) { string fileName = $"{DateTime.Now.Ticks}.jpg"; var imagePath = ImagemHelper.Save(ImageType.Perfil, Server, model.ImageFile); var user = await UserManager.FindByIdAsync(User.Identity.GetUserId()); user.ImagePath = imagePath; var result = await UserManager.UpdateAsync(user); if (result.Succeeded) { if (user != null) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); } return(RedirectToAction("Index", new { Message = MessageType.ChangeImageSuccess })); } AddErrors(result); return(View()); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var imagePath = ImagemHelper.Save(ImageType.Perfil, Server, model.ImageFile); var user = new ApplicationUser { Name = model.Name, Surnames = model.Surnames, UserName = model.UserName, Email = model.Email, ImagePath = imagePath }; _wallet.Create(user.Id); var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); return(RedirectToAction("Index", "Home")); } AddErrors(result); } return(View(model)); }