public IHttpActionResult PutClientType(int id, ClientType clientType) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != clientType.ClientType_ID) { return(BadRequest()); } db.Entry(clientType).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ClientTypeExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutBookingRecord(int id, BookingRecord bookingRecord) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != bookingRecord.BookingRecord_ID) { return(BadRequest()); } db.Entry(bookingRecord).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!BookingRecordExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutRoom(int id, Room room) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != room.Room_ID) { return(BadRequest()); } db.Entry(room).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!RoomExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutAddress(int id, Address address) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != address.Address_ID) { return(BadRequest()); } db.Entry(address).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AddressExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutProperty(int id, Property property) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != property.Property_ID) { return(BadRequest()); } db.Entry(property).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PropertyExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutCard(string id, Card card) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != card.Card_Number) { return(BadRequest()); } db.Entry(card).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CardExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Index(UserViewModel objUserViewModel) { string message = string.Empty; string ImageUniqueName = String.Empty; string ActualImageName = String.Empty; if (objUserViewModel.Id == 0) { //get value for img ImageUniqueName = Guid.NewGuid().ToString(); if (objUserViewModel != null && objUserViewModel.Image != null) { ActualImageName = ImageUniqueName + Path.GetExtension(objUserViewModel.Image.FileName); objUserViewModel.Image.SaveAs(Server.MapPath("~/UserImages/" + ActualImageName)); } //Insert new a User to database User obj = new User() { UserName = objUserViewModel.UserName, PassWord = Encrypt(objUserViewModel.PassWord), FullName = objUserViewModel.FullName, Email = objUserViewModel.Email, RoleId = objUserViewModel.RoleId, IsActive = true, UserImage = ActualImageName, PhoneNumber = objUserViewModel.PhoneNumber, }; objBookingDBEntities.Users.Add(obj); message = "Added."; } else { User obj = objBookingDBEntities.Users.Single(model => model.Id == objUserViewModel.Id && model.IsActive == true); //get value for img if (objUserViewModel.Image != null) { ImageUniqueName = Guid.NewGuid().ToString(); ActualImageName = ImageUniqueName + Path.GetExtension(objUserViewModel.Image.FileName); objUserViewModel.Image.SaveAs(Server.MapPath("~/UserImages/" + ActualImageName)); obj.UserImage = ActualImageName; } //Edit a User obj.UserName = objUserViewModel.UserName; if (!string.IsNullOrEmpty(objUserViewModel.PassWord)) { obj.PassWord = Encrypt(objUserViewModel.PassWord); } obj.FullName = objUserViewModel.FullName; obj.PhoneNumber = objUserViewModel.PhoneNumber; obj.Email = objUserViewModel.Email; obj.RoleId = objUserViewModel.RoleId; obj.IsActive = true; message = "Updated."; } objBookingDBEntities.SaveChanges(); return(Json(new { message = "User Successfully " + message, success = true }, JsonRequestBehavior.AllowGet)); }
public bool UpdateEntityInDb(object updatedUser) { bool entityUpdated = false; using (var db = new BookingDBEntities()) { db.Entry(updatedUser).State = EntityState.Modified; bool saveFailed; do { saveFailed = false; try { db.SaveChanges(); // saves changes in DB entityUpdated = true; } catch (DbUpdateConcurrencyException ex) { saveFailed = true; ex.Entries.Single().Reload(); // reloads entity from DB entityUpdated = false; } } while (saveFailed); } return(entityUpdated); }
public ActionResult Index(BookingViewModel objBookingViewModel) { //Users can only choose a maximum of 2 time frames in a day int userID = 0; if (Session["LogedUserID"] != null) { userID = Convert.ToInt32(Session["LogedUserID"]); } int UserHour = objBookingDBEntities.RoomUsages.Count(model => model.UserID == userID && model.BookingDate.Year == objBookingViewModel.BookingDate.Year && model.BookingDate.Month == objBookingViewModel.BookingDate.Month && model.BookingDate.Day == objBookingViewModel.BookingDate.Day && model.IsActive == true); if (UserHour >= 2) { return(Json(new { message = "Users can only choose maximum 2 time frames in a day.", success = true }, JsonRequestBehavior.AllowGet));; } RoomUsage obj = new RoomUsage() { RoomId = objBookingViewModel.RoomId, BookingHoursID = objBookingViewModel.BookingHourID, BookingDate = objBookingViewModel.BookingDate, UserID = userID, NumberOfMembers = objBookingViewModel.NumberOfMembers, IsActive = true }; objBookingDBEntities.RoomUsages.Add(obj); objBookingDBEntities.SaveChanges(); return(Json(new { message = "Booking Successfully Created.", success = true }, JsonRequestBehavior.AllowGet)); }
//Delete Room Booking public JsonResult DeleteRoomUsageDetails(int roomUsageId) { #region Get booked room // Get booked room based on Id when user click on booked room to delete. // System will update IsActive = false, when load booked rooms the system will // load all booked rooms with IsActive = true RoomUsage objRoomUsage = objBookingDBEntities.RoomUsages.Single(model => model.Id == roomUsageId); objRoomUsage.IsActive = false; objBookingDBEntities.SaveChanges(); #endregion #region Get user login //Get user based on user's login on the system. string userName = (string)Session["UserName"]; User u = objBookingDBEntities.Users.Single(model => model.UserName == userName); #endregion #region Send Email // if user has role is "Admin", the system will send an email to the user with // room information that has been deleted. if (u.Role != null && u.Role.Name == "Admin") { //Send email string content = System.IO.File.ReadAllText(Server.MapPath("~/Views/Shared/_TemplateSendEmail.cshtml")); content = content.Replace("{{RoomNumber}}", objRoomUsage.Room.RoomNumber); content = content.Replace("{{BookingDate}}", objRoomUsage.BookingDate.ToString("dd-MMM-yyyy")); content = content.Replace("{{BookingHours}}", objRoomUsage.BookingHour.Name); SendMail(objRoomUsage.User.Email, "Your room booking has been cancelled.", content); //End Send email } #endregion return(Json(new { message = "Record Successfully Deleted.", success = true }, JsonRequestBehavior.AllowGet)); }
public IHttpActionResult UserAccountBooking(UserAccountBookingDTO booking) // BOOKING WITH USER ACCOUNT, NOT FINISHED { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } TextResult httpResponse = new TextResult("", msg); SeatManager smgr = new SeatManager(); CustomerManager cmgr = new CustomerManager(); BookingManager bmgr = new BookingManager(); UserAccountsManager umgr = new UserAccountsManager(); DateTime currentDate = DateTime.Now; string token = umgr.CreateToken(booking.AccountName); var loginOk = umgr.CheckIfUserIsLoggedIn(booking.LoginToken, token); // token passed from frontend to check if user is logged in, token variabel content? if (loginOk.Equals(false)) { httpResponse.ChangeHTTPMessage("User is not logged in!", msg); return(httpResponse); } ; var convertedForDate = bmgr.DateTimeConverter(booking.BookingForDate); // Converting dates into DateTime objects if (convertedForDate.Equals(null)) // checking if date input is valid { httpResponse.ChangeHTTPMessage("Date input is not correct!", msg); return(httpResponse); } ; int?allSeatsId = smgr.GetSeatPlacementId(booking.RowNumber, booking.SeatNumber); // Gets the allSeatsId from AllSeats from row and seatnumber int bookingId = smgr.CheckIfSeatIsTaken(convertedForDate, allSeatsId); // checks if seat is taken, returns bookingId if (bookingId != 0) { httpResponse.ChangeHTTPMessage("That seat is taken!", msg); // http response if seat is taken return(httpResponse); } var custId = umgr.GetCustomerIdFromUserAccountName(booking.AccountName); var email = cmgr.GetCustomerEmailFromAccountName(custId); var bookingEntity = bmgr.UserAccountBooking(allSeatsId, custId, convertedForDate, currentDate); db.Bookings.Add(bookingEntity); db.SaveChanges(); httpResponse.ChangeHTTPMessage("Booking has been made!", msg); // HTTP response if fails to savechanges to DB return(httpResponse); }
public IHttpActionResult CreateUserAccount(RegistrationDTO userInput) // CREATE ACCOUNT { TextResult httpResponse = new TextResult("There is already an account with that name!", msg); UserAccountsManager umgr = new UserAccountsManager(); CustomerManager cmgr = new CustomerManager(); if (!ModelState.IsValid) { return(BadRequest()); } bool EmailIsOk = cmgr.IsValidEmail(userInput.Email); if (EmailIsOk.Equals(false)) { httpResponse.ChangeHTTPMessage("Enter valid email!", msg); return(httpResponse); // HTTP response if accountname already exists } ; bool accNameExist = umgr.CheckIfAccountNameExists(userInput.AccountName); // Check if username already exists, returns bool if (accNameExist.Equals(true)) { return(httpResponse); // HTTP response if accountname already exists } ; bool emailExists = cmgr.CheckIfEmailExists(userInput.Email); // check if email already exists, returns bool if (emailExists.Equals(true)) { httpResponse.ChangeHTTPMessage("Email already exists!", msg); // If email exists, HTTP response return(httpResponse); } ; bool passwordIsNotOk = umgr.CheckIfPasswordIsOk(userInput.AccountPassword); // checks if password is ok if (passwordIsNotOk.Equals(true)) { httpResponse.ChangeHTTPMessage("Password must contain atleast six characters, one digit and one uppercase!", msg); // If password is not ok, HTTP response return(httpResponse); } ; var customerObject = cmgr.AddCustomer(userInput.Email); // Creates customer entity var userObject = umgr.CreateUserAccount(userInput.AccountName, userInput.AccountPassword, userInput.PhoneNumber, userInput.CustomerName, customerObject); // creates useraccount entity try { db.Customers.Add(customerObject); // adds customer entity to DB db.UserAccounts.Add(userObject); // adds useraccount to DB db.SaveChanges(); } catch { httpResponse.ChangeHTTPMessage("Failed to create account!", msg); // HTTP response if fails to savechanges to DB return(httpResponse); } return(Ok()); // returns login token if registration succesfull }
public ActionResult Index(BookingViewModel objBookingViewModel) { try { // Uncomment below throw exception to test Singleton Logger for booking // throw new System.NullReferenceException("Booking is not valid."); //Users can only choose a maximum of 2 time frames in a day int userID = 0; if (Session["LogedUserID"] != null) { userID = Convert.ToInt32(Session["LogedUserID"]); } int UserHour = objBookingDBEntities.RoomUsages.Count(model => model.UserID == userID && model.BookingDate.Year == objBookingViewModel.BookingDate.Year && model.BookingDate.Month == objBookingViewModel.BookingDate.Month && model.BookingDate.Day == objBookingViewModel.BookingDate.Day && model.IsActive == true); if (UserHour >= 2) { return(Json(new { message = "Users can only choose maximum 2 time frames in a day.", success = true }, JsonRequestBehavior.AllowGet));; } //Users cannot book a room already booked int UserBooked = objBookingDBEntities.RoomUsages.Count(model => model.BookingDate.Year == objBookingViewModel.BookingDate.Year && model.BookingDate.Month == objBookingViewModel.BookingDate.Month && model.BookingDate.Day == objBookingViewModel.BookingDate.Day && model.BookingHoursID == objBookingViewModel.BookingHourID && model.RoomId == objBookingViewModel.RoomId && model.IsActive == true); if (UserBooked >= 1) { return(Json(new { message = "The room has already been booked.", success = true }, JsonRequestBehavior.AllowGet));; } RoomUsage obj = new RoomUsage() { RoomId = objBookingViewModel.RoomId, BookingHoursID = objBookingViewModel.BookingHourID, BookingDate = objBookingViewModel.BookingDate, UserID = userID, NumberOfMembers = objBookingViewModel.NumberOfMembers, IsActive = true }; objBookingDBEntities.RoomUsages.Add(obj); objBookingDBEntities.SaveChanges(); return(Json(new { message = "Booking Successfully Created.", success = true }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { MyLogger.Instance.TraceEvent(TraceEventType.Error, 0, System.DateTime.Now.ToString() + ": Booking fail with error: " + ex.Message); return(Json(new { message = "Booking not successful. Please try again.", success = true }, JsonRequestBehavior.AllowGet)); } }
public IHttpActionResult PostUserAccounts(UserAccounts userAccounts) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.UserAccounts.Add(userAccounts); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = userAccounts.userAccountId }, userAccounts)); }
public IHttpActionResult PostCustomers(Customers customers) // Adds new customer { TextResult httpResponse = new TextResult("Enter valid email!", msg); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } CustomerManager cmgr = new CustomerManager(); bool EmailIsOk = cmgr.IsValidEmail(customers.email); if (EmailIsOk.Equals(false)) { return(httpResponse); // HTTP response if accountname already exists } ; bool emailExists = cmgr.CheckIfEmailExists(customers.email); // Check if email exists if (emailExists.Equals(true)) { httpResponse.ChangeHTTPMessage("Email already exists!", msg); // Http response return(httpResponse); } var customerObject = cmgr.AddCustomer(customers.email); // creates new customer entity try { db.Customers.Add(customerObject); // adds customer entity to db db.SaveChanges(); } catch { TextResult FailedToCreateCustomer = new TextResult("Failed to create customer", msg); return(FailedToCreateCustomer); } httpResponse.ChangeHTTPMessage("Account created!", msg); // Http response return(httpResponse); }
public ActionResult Index(UserViewModel objUserViewModel) { string message = string.Empty; if (objUserViewModel.Id == 0) { //Insert new a User to database User obj = new User() { UserName = objUserViewModel.UserName, PassWord = objUserViewModel.PassWord, FullName = objUserViewModel.FullName, Email = objUserViewModel.Email, RoleId = objUserViewModel.RoleId, IsActive = true }; objBookingDBEntities.Users.Add(obj); message = "Added."; } else { //Edit a User User obj = objBookingDBEntities.Users.Single(model => model.Id == objUserViewModel.Id); obj.UserName = objUserViewModel.UserName; if (!string.IsNullOrEmpty(objUserViewModel.PassWord.Trim())) { obj.PassWord = objUserViewModel.PassWord; } obj.FullName = objUserViewModel.FullName; obj.Email = objUserViewModel.Email; obj.RoleId = objUserViewModel.RoleId; obj.IsActive = true; message = "Updated."; } objBookingDBEntities.SaveChanges(); return(Json(new { message = "User Successfully " + message, success = true }, JsonRequestBehavior.AllowGet)); }
public IHttpActionResult PostMovieShowings(MovieShowingDTO movieShowings) // ADD NEW MOVIE SHOWING { MoviesManager mvmgr = new MoviesManager(); BookingManager bmgr = new BookingManager(); TextResult httpResponse = new TextResult("", msg); DateTime convertedShowingDate = new DateTime(); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } convertedShowingDate = bmgr.DateTimeConverter(movieShowings.MovieShowingTime); int?showingExists = mvmgr.CheckIfMovieShowingExists(convertedShowingDate); // Checks if movieshowing already exists if (showingExists != 0) { httpResponse.ChangeHTTPMessage("Showing already exists on that date!", msg); // http response return(httpResponse); } int?movieId = mvmgr.CheckIfMovieExists(movieShowings.MovieName); var movieShowingEntity = mvmgr.AddNewMovieShowing(convertedShowingDate, movieId, movieShowings.LoungeId); // creates movieshowing entity try { db.MovieShowings.Add(movieShowingEntity); db.SaveChanges(); } catch { httpResponse.ChangeHTTPMessage("Movieshowing could not be added!", msg); return(httpResponse); } httpResponse.ChangeHTTPMessage("Movieshowing added!", msg); return(httpResponse); }
public IHttpActionResult PostMovies(Movies movies) // ADD NEW MOVIE TO DATABASE { TextResult httpResponse = new TextResult("Movie added!", msg); MoviesManager mvmgr = new MoviesManager(); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } int movieExists = mvmgr.CheckIfMovieExists(movies.movieName); // returns 0 if movie exists if (movieExists != 0) { httpResponse.ChangeHTTPMessage("Movie already exists!", msg); return(httpResponse); } var movieEntity = mvmgr.AddNewMovie(movies.movieName); db.Movies.Add(movieEntity); db.SaveChanges(); return(httpResponse); }
public ActionResult Index(RoomViewModel objRoomViewModel) { string message = string.Empty; if (objRoomViewModel.Id == 0) { //Insert new a Room to database Room obj = new Room() { RoomNumber = objRoomViewModel.RoomNumber, RoomPrice = objRoomViewModel.RoomPrice, RoomTypeid = objRoomViewModel.RoomTypeId, RoomCapacity = objRoomViewModel.RoomCapacity, RoomDescription = objRoomViewModel.RoomDescription, StudentsNotAllowed = objRoomViewModel.StudentsNotAllowed, IsActive = true }; objBookingDBEntities.Rooms.Add(obj); message = "Added."; } else { //Edit a Room Room obj = objBookingDBEntities.Rooms.Single(model => model.Id == objRoomViewModel.Id); obj.RoomNumber = objRoomViewModel.RoomNumber; obj.RoomPrice = objRoomViewModel.RoomPrice; obj.RoomTypeid = objRoomViewModel.RoomTypeId; obj.RoomCapacity = objRoomViewModel.RoomCapacity; obj.RoomDescription = objRoomViewModel.RoomDescription; obj.StudentsNotAllowed = objRoomViewModel.StudentsNotAllowed; obj.IsActive = true; message = "Updated."; } objBookingDBEntities.SaveChanges(); return(Json(new { message = "Room Successfully " + message, success = true }, JsonRequestBehavior.AllowGet)); }
public IHttpActionResult DeleteUserAccounts(AccountNameDTO accName) { UserAccountsManager umgr = new UserAccountsManager(); CustomerManager cmgr = new CustomerManager(); var user = umgr.GetUserAccountByName(accName.AccountName); var customer = cmgr.GetCustomerEntityFromId(user.customerId); try { db.UserAccounts.Remove(user); db.Customers.Remove(customer); db.SaveChanges(); } catch { TextResult httpResponse = new TextResult("Failed to delete account!", msg); // Http response return(httpResponse); } return(Ok()); }