Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(string id, [Bind("firstName,lastName,gender,deletedByAdmin,Id,UserName,NormalizedUserName,Email,NormalizedEmail,EmailConfirmed,PasswordHash,SecurityStamp,ConcurrencyStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEnd,LockoutEnabled,AccessFailedCount")] User user)
        {
            if (id != user.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(user);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                bool isAdmin = await this.userManager.IsInRoleAsync(user, "Admin");

                if (isAdmin)
                {
                    return(RedirectToAction(nameof(UserController.Index), "User"));
                }
                else
                {
                    return(RedirectToAction(nameof(HomeController.Index), "Home"));
                }
            }
            return(View(user));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create(CreateAuctionModel auctionModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(auctionModel));
            }

            // Dohvatam ID ulogovanog Usera
            string loggedUserId = User.FindFirst("id").Value;

            Auction auction = new Auction( )
            {
                name         = auctionModel.name,
                description  = auctionModel.description,
                startPrice   = auctionModel.startPrice,
                currentPrice = auctionModel.startPrice,
                createDate   = DateTime.Now,
                openDate     = auctionModel.openDate,
                closeDate    = auctionModel.closeDate,
                state        = Auction.AuctionState.DRAFT,
                ownerId      = loggedUserId,
                owner        = await _context.Users.FirstOrDefaultAsync(u => u.Id.Equals(loggedUserId))
            };


            using (BinaryReader reader = new BinaryReader(auctionModel.image.OpenReadStream( ))) {
                auction.image = reader.ReadBytes(Convert.ToInt32(reader.BaseStream.Length));
            };

            _context.Add(auction);
            await _context.SaveChangesAsync();

            if (User.FindFirst(ClaimTypes.Role).Value == "Admin")
            {
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(RedirectToAction(nameof(MyAuctions), "Auction"));
            }
        }