public IActionResult Create(UsersCreateViewModel createModel) { if (GlobalVar.LoggedOnUserRights != GlobalVar.UserRights.Admininstrator && context.Users.Where(x => x.IsActive).Count() != 0) { UsersLogInViewModel model1 = new UsersLogInViewModel(); model1.Message = "Нямате право на това действие. Моля, влезте в акаунта си."; return(View("LogIn", model1)); } createModel.Message = null; if (ModelState.IsValid) { if (!DoesPasswordsMatch(createModel.Password, createModel.ConfirmPassword)) { createModel.Message = "Двете пароли не съвпадат"; return(View(createModel)); } try { Validate(new Validation_User() { Username = createModel.Username, UserId = -1 }); } catch (InvalidOperationException e) { createModel.Message = e.Message; return(View(createModel)); } User user = new User { Username = createModel.Username, Password = createModel.Password, FirstName = createModel.FirstName, MiddleName = createModel.MiddleName, LastName = createModel.LastName, EGN = createModel.EGN, Email = createModel.Email, TelephoneNumber = createModel.TelephoneNumber }; context.Users.Add(user); context.SaveChanges(); if (context.Users.Where(x => x.IsActive).Count() == 1) { GlobalVar.LoggedOnUserId = context.Users.Where(x => x.IsActive).First().Id; GlobalVar.LoggedOnUserRights = GlobalVar.UserRights.Admininstrator; } return(RedirectToAction(nameof(Index))); } return(View(createModel)); }
public IActionResult Create(UsersCreateViewModel createModel) { if (GlobalVar.LoggedOnUserRights != GlobalVar.UserRights.Admininstrator && _context.Users.Where(x => x.IsActive).Count() != 0) { UsersLogInViewModel model1 = new UsersLogInViewModel(); model1.Message = "You dont meet the required permission to do this. Please, log in into account with admin permissions"; return(View("LogIn", model1)); } createModel.Message = null; if (ModelState.IsValid) { if (!DoesPasswordsMatch(createModel.Password, createModel.ConfirmPassword)) { createModel.Message = "Password and confirm password should match"; return(View(createModel)); } try { Validate(new Validation_User() { Username = createModel.Username, UserId = -1 }); } catch (InvalidOperationException e) { createModel.Message = e.Message; return(View(createModel)); } User user = new User { Username = createModel.Username, Password = createModel.Password, FirstName = createModel.FirstName, MiddleName = createModel.MiddleName, LastName = createModel.LastName, EGN = createModel.EGN, Email = createModel.Email, TelephoneNumber = createModel.TelephoneNumber }; _context.Users.Add(user); _context.SaveChanges(); if (_context.Users.Where(x => x.IsActive).Count() == 1) { GlobalVar.LoggedOnUserId = _context.Users.Where(x => x.IsActive).First().Id; GlobalVar.LoggedOnUserRights = GlobalVar.UserRights.Admininstrator; } return(RedirectToAction(nameof(Index))); } return(View(createModel)); }
public IActionResult Create(RoomsCreateViewModel createModel) { if (GlobalVar.LoggedOnUserRights != GlobalVar.UserRights.Admininstrator) { return(RedirectToAction("LogInPermissionDenied", "Users")); } createModel.Message = null; if (ModelState.IsValid) { try { Validate(new Validation_Room() { Capacity = createModel.Capacity, Number = createModel.Number }); } catch (InvalidOperationException e) { createModel.Message = e.Message; return(View(createModel)); } if (_context.Rooms.Where(x => x.Number == createModel.Number).Count() > 0) { createModel.Message = $"Room cant be created becuase there's already an existing room with the given number ({createModel.Number})"; return(View(createModel)); } Room room = new Room { Number = createModel.Number, PriceAdult = createModel.PriceAdult, PriceChild = createModel.PriceChild, Type = (int)createModel.RoomType, Capacity = createModel.Capacity }; _context.Rooms.Add(room); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); } return(RedirectToAction(nameof(Index))); }
public IActionResult Create(RoomsCreateViewModel createModel) { if (GlobalVar.LoggedOnUserRights != GlobalVar.UserRights.Admininstrator) { return(RedirectToAction("LogInPermissionDenied", "Users")); } createModel.Message = null; if (ModelState.IsValid) { try { Validate(new Validation_Room() { Capacity = createModel.Capacity, Number = createModel.Number }); } catch (InvalidOperationException e) { createModel.Message = e.Message; return(View(createModel)); } if (context.Rooms.Where(x => x.Number == createModel.Number).Count() > 0) { createModel.Message = $"Вече е създадена стая със следния номер: ({createModel.Number})"; return(View(createModel)); } Room room = new Room { Number = createModel.Number, PriceAdult = createModel.PriceAdult, PriceChild = createModel.PriceChild, Type = (int)createModel.RoomType, Capacity = createModel.Capacity }; context.Rooms.Add(room); context.SaveChanges(); return(RedirectToAction(nameof(Index))); } return(RedirectToAction(nameof(Index))); }
public IActionResult Create(ReservationsCreateViewModel createModel) { if (GlobalVar.LoggedOnUserId == -1) { return(RedirectToAction("LogInRequired", "Users")); } if (ModelState.IsValid) { try { Validate(new Validation_Reservation() { DateOfAccommodation = createModel.DateOfAccommodation, DateOfExemption = createModel.DateOfExemption, RoomId = createModel.RoomId, ReservationId = -1 }); } catch (InvalidOperationException e) { createModel = CreateReservationVMWithDropdown(createModel, e.Message); return(View(createModel)); } Reservation reservation = new Reservation { UserId = createModel.UserId, RoomId = createModel.RoomId, DateOfAccommodation = createModel.DateOfAccommodation, DateOfExemption = createModel.DateOfExemption, IsAllInclusive = createModel.IsAllInclusive, IsBreakfastIncluded = createModel.IsBreakfastIncluded, OverallBill = 0 }; _context.Reservations.Add(reservation); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); } createModel = CreateReservationVMWithDropdown(createModel, null); return(View(createModel)); }