Exemple #1
0
        public async Task <IActionResult> Register(Register model)
        {
            if (ModelState.IsValid)
            {
                User user = await _context.Users.FirstOrDefaultAsync(s => s.Email == model.Email);

                if (user == null)
                {
                    Role role = await _context.Roles.FirstOrDefaultAsync(s => s.Name == "Employee");

                    user = new User()
                    {
                        Name     = model.Name,
                        Role     = role,
                        Email    = model.Email,
                        Password = model.Password
                    };
                    _context.Users.Add(user);
                    await _context.SaveChangesAsync();
                    await Authenticate(user);

                    return(RedirectToAction("Index", "Rooms"));
                }
                else
                {
                    ModelState.AddModelError("", "User already exist");
                }
            }
            return(View(model));
        }
        public async Task <IActionResult> Add([Bind("Name,Descrtiption,Seats,Projector,Board")] Room room)
        {
            if (ModelState.IsValid)
            {
                _context.Add(room);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(room));
        }
Exemple #3
0
        public async Task <IActionResult> Add([Bind("Start,End,UserId,RoomId")] Reservation reservation, int?roomid)
        {
            reservation.Status = Status.Idle;
            if (ModelState.IsValid)
            {
                _context.Add(reservation);
                await _context.SaveChangesAsync();

                if (roomid == null)
                {
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    return(Redirect($"/Rooms/Details/{roomid}"));
                }
            }
            ViewData["Status"] = new SelectList(Statuses, Statuses.ToString());
            ViewData["RoomId"] = new SelectList(_context.Rooms, "Id", "Name", reservation.RoomId);
            ViewData["UserId"] = new SelectList(_context.Users, "Id", "Name", reservation.UserId);
            return(View(reservation));
        }
Exemple #4
0
 public async Task <bool> SaveAllAsync()
 {
     return(await _context.SaveChangesAsync() > 0);
 }