/// <summary> /// Deletes employee user depending if the uderID already exists /// </summary> /// <param name="userID">the user that is being deleted</param> /// <returns>list of users</returns> public void DeleteUserEmployee(int userID) { try { using (HotelDBEntities context = new HotelDBEntities()) { bool isUser = IsUserID(userID); // Deletes the employee for (int i = 0; i < GetAllEmployees().Count; i++) { if (GetAllEmployees()[i].UserID == userID) { tblEmployee emp = (from r in context.tblEmployees where r.UserID == userID select r).First(); context.tblEmployees.Remove(emp); context.SaveChanges(); } } if (isUser == true) { tblUser userToDelete = (from r in context.tblUsers where r.UserID == userID select r).First(); context.tblUsers.Remove(userToDelete); context.SaveChanges(); } else { MessageBox.Show("Cannot delete the user"); } } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); } }
public IHttpActionResult PutCam(CamereClass camera) { var update_results = hotel.spCRUDCamere(camera.ID, camera.Capacitate, camera.Pret, "Update").ToList(); hotel.SaveChanges(); return(Ok(update_results)); }
public IHttpActionResult PutSer(ServiciiClass serviciu) { var update_results = hotel.spCRUDServicii(serviciu.ID, serviciu.Nume, serviciu.Pret, "Update").ToList(); hotel.SaveChanges(); return(Ok(update_results)); }
public ActionResult NewOrder(string passport, string fio, string phone, string room_num, string order_type, string begin_date, string end_date, string emp) { try { using (HotelDBEntities db = new HotelDBEntities()) { Клиенты client = new Клиенты(); client.Паспорт = passport; client.ФИО = fio; client.Телефон = phone; db.Клиенты.Add(client); db.SaveChanges(); var clinet_id = db.Клиенты.Where(x => x.Паспорт == passport).Select(x => x.ID_клиента).FirstOrDefault(); Учет record = new Учет(); record.ID_Клиента = clinet_id; record.ID_Номера = Convert.ToInt32(room_num) + 1; record.Операция = Convert.ToInt32(order_type); record.Дата_въезда = Convert.ToDateTime(begin_date); record.Дата_выезда = Convert.ToDateTime(end_date); var emp_id = db.Сотрудники.Where(x => x.Имя == emp).Select(x => x.ID_сотрудника).FirstOrDefault(); record.Сотрудник = emp_id; int room_id = Convert.ToInt32(room_num) + 1; var room_price = db.Номера.Where(x => x.ID == room_id).Select(x => x.Цена).FirstOrDefault(); record.Цена = Convert.ToDateTime(end_date).Subtract(Convert.ToDateTime(begin_date)).Days *room_price; db.Учет.Add(record); db.SaveChanges(); } } catch { return(RedirectToAction("Index")); } return(RedirectToAction("Index")); }
public void CreateReservation(Reservation reservation) { entity.Reservations.Add(reservation); entity.SaveChanges(); }
public Room AddRoom(RoomViewModel roomViewModel) { string ImageUnique = Guid.NewGuid().ToString(); string actualImage = ImageUnique + Path.GetExtension(roomViewModel.Image.FileName); roomViewModel.Image.SaveAs(HttpContext.Current.Server.MapPath("~/Images/" + actualImage)); Room room = new Room() { RoomNumber = roomViewModel.RoomNumber, RoomDescription = roomViewModel.RoomDescription, RoomPrice = roomViewModel.RoomPrice, BookingStatusId = roomViewModel.BookingStatusId, RoomTypeId = roomViewModel.RoomTypeId, RoomCapacity = roomViewModel.RoomCapacity, RoomImage = actualImage, isActive = true }; dbContext.Rooms.Add(room); if (dbContext.SaveChanges() > 0) { return(room); } return(null); }
public IHttpActionResult PutDot(DotariClass dotare) { var update_results = hotel.spCRUDDotari(dotare.ID, dotare.Nume, dotare.Pret, "Update").ToList(); hotel.SaveChanges(); return(Ok(update_results)); }
public ActionResult Index(BookingViewModel objBookingViewModel) { int numberOfDays = Convert.ToInt32((objBookingViewModel.BookingTo - objBookingViewModel.BookingFrom).TotalDays); Room objRoom = objHotelDBEntities.Rooms.Single(model => model.RoomId == objBookingViewModel.AssignRoomId); decimal RoomPrice = objRoom.RoomPrice; decimal TotalAmount = RoomPrice * numberOfDays; RoomBooking roomBooking = new RoomBooking() { BookingFrom = objBookingViewModel.BookingFrom, BookingTo = objBookingViewModel.BookingTo, AssignRoomId = objBookingViewModel.AssignRoomId, CustomerAddress = objBookingViewModel.CustomerAddress, CustomerName = objBookingViewModel.CustomerName, CustomerPhone = objBookingViewModel.CustomerPhone, NoOfMembers = objBookingViewModel.NumberOfMembers, TotalAmount = TotalAmount }; objHotelDBEntities.RoomBookings.Add(roomBooking); objHotelDBEntities.SaveChanges(); objRoom.BookingStatusId = 3; objHotelDBEntities.SaveChanges(); return(Json(data: new { message = "Hotel Booking is Successfull Created.", success = true }, JsonRequestBehavior.AllowGet)); }
// Method that add Manager to database public void AddManager(vwManager manager) { try { using (HotelDBEntities context = new HotelDBEntities()) { tblUser newUser = new tblUser(); tblManager newManager = new tblManager(); newUser.Name = manager.Name; newUser.Surname = manager.Surname; newUser.DateOfBirth = manager.DateOfBirth; newUser.Email = manager.Email; newUser.Username = manager.Username; newUser.Password = SecurePasswordHasher.Hash(manager.Password); context.tblUsers.Add(newUser); context.SaveChanges(); manager.UserId = newUser.UserId; newManager.UserId = manager.UserId; newManager.Floor = manager.Floor; newManager.Experience = manager.Experience; newManager.Qualifications = manager.Qualifications; context.tblManagers.Add(newManager); context.SaveChanges(); manager.ManagerID = newManager.ManagerID; } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); } }
public ActionResult Create([Bind(Include = "GuestNo,GuestName,GuestAddress")] Guests guests) { if (ModelState.IsValid) { db.Guests.Add(guests); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(guests)); }
public ActionResult Create([Bind(Include = "HotelNo,HotelName,HotelAddress")] Hotel hotel) { if (ModelState.IsValid) { db.Hotel.Add(hotel); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(hotel)); }
public ActionResult Index(RoomViewModel objRoomViewModel) { string message = String.Empty; string ImageUniqueName = String.Empty; string ActualImageName = String.Empty; if (objRoomViewModel.RoomId == 0) { ImageUniqueName = Guid.NewGuid().ToString(); ActualImageName = ImageUniqueName + Path.GetExtension(objRoomViewModel.Image.FileName); objRoomViewModel.Image.SaveAs(Server.MapPath("~/RoomImages/" + ActualImageName)); //objHotelDBEntities Room objRoom = new Room() { RoomNumber = objRoomViewModel.RoomNumber, RoomImage = ActualImageName, RoomPrice = objRoomViewModel.RoomPrice, BookingStatusId = objRoomViewModel.BookingStatusId, RoomTypeId = objRoomViewModel.RoomTypeId, RoomCapacity = objRoomViewModel.RoomCapacity, RoomDescription = objRoomViewModel.RoomDescription, IsActive = true }; objHotelDBEntities.Rooms.Add(objRoom); message = "Added."; } else { Room objRoom = objHotelDBEntities.Rooms.Single(model => model.RoomId == objRoomViewModel.RoomId); if (objRoomViewModel.Image != null) { ImageUniqueName = Guid.NewGuid().ToString(); ActualImageName = ImageUniqueName + Path.GetExtension(objRoomViewModel.Image.FileName); objRoomViewModel.Image.SaveAs(Server.MapPath("~/RoomImages/" + ActualImageName)); objRoom.RoomImage = ActualImageName; } objRoom.RoomNumber = objRoomViewModel.RoomNumber; objRoom.RoomPrice = objRoomViewModel.RoomPrice; objRoom.BookingStatusId = objRoomViewModel.BookingStatusId; objRoom.RoomTypeId = objRoomViewModel.RoomTypeId; objRoom.RoomCapacity = objRoomViewModel.RoomCapacity; objRoom.RoomDescription = objRoomViewModel.RoomDescription; objRoom.IsActive = true; message = "Updated."; } objHotelDBEntities.SaveChanges(); return(Json(new { message = "Room Successfully " + message, success = true }, JsonRequestBehavior.AllowGet)); }
public ActionResult Create([Bind(Include = "Owner_id,Account_id,FirstName,LastName,Password,Contact_detail")] Hotel_Owner hotel_Owner) { if (ModelState.IsValid) { db.Hotel_Owner.Add(hotel_Owner); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(hotel_Owner)); }
public ActionResult Create([Bind(Include = "Hotel_id,Name,Address,Number_of_room,Hotel_OwnerOwner_id")] Hotel hotel) { if (ModelState.IsValid) { db.Hotels.Add(hotel); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Hotel_OwnerOwner_id = new SelectList(db.Hotel_Owner, "Owner_id", "Account_id", hotel.Hotel_OwnerOwner_id); return(View(hotel)); }
/// <summary> /// Creates a employee /// </summary> /// <param name="manager">employee to add</param> /// <returns>a new employee</returns> public vwEmployee AddEmployee(vwEmployee employee) { if (v.ValidEmployeeInput(employee)) { try { using (HotelDBEntities context = new HotelDBEntities()) { employee.DateOfBirth = employee.DateOfBirth; //user tblUser newManager = new tblUser(); newManager.Name = employee.Name; newManager.DateOfBirth = employee.DateOfBirth; newManager.Email = employee.Email; newManager.Username = employee.Username; newManager.Password = employee.Password; context.tblUsers.Add(newManager); context.SaveChanges(); //employee int id = getUserId(employee.Username); tblEmployee man = new tblEmployee(); man.Floor = employee.Floor; man.Citizenship = employee.Citizenship; man.Gender = employee.Gender; man.Engagement = employee.Engagement; man.UserID = id; man.Salary = "0"; context.tblEmployees.Add(man); context.SaveChanges(); employee.UserID = newManager.UserID; return(employee); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } } else { MessageBox.Show("Wrong data input. Please provide valid data to add new employee."); return(null); } }
public ActionResult Create([Bind(Include = "BookingID,HotelNo,GuestNo,DateFrom,DateTo,RoomNo")] Booking booking) { if (ModelState.IsValid) { db.Booking.Add(booking); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.RoomNo = new SelectList(db.Room, "RoomNo", "RoomType", booking.RoomNo); ViewBag.GuestNo = new SelectList(db.Guests, "GuestNo", "GuestName", booking.GuestNo); return(View(booking)); }
/// <summary> /// Creates a manager /// </summary> /// <param name="manager">manager to add</param> /// <returns>a new manager</returns> public vwManager AddManager(vwManager manager) { if (v.ValidManagerInput(manager)) { try { using (HotelDBEntities context = new HotelDBEntities()) { manager.DateOfBirth = manager.DateOfBirth; //user tblUser newManager = new tblUser(); newManager.Name = manager.Name; newManager.DateOfBirth = manager.DateOfBirth; newManager.Email = manager.Email; newManager.Username = manager.Username; newManager.Password = manager.Password; context.tblUsers.Add(newManager); context.SaveChanges(); //manager int id = getUserId(manager.Username); tblManager man = new tblManager(); man.Floor = manager.Floor; man.Experience = manager.Experience; man.QualificationsLevel = manager.QualificationsLevel; man.UserID = id; context.tblManagers.Add(man); context.SaveChanges(); manager.UserID = newManager.UserID; return(manager); } } catch (Exception ex) { Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } } else { MessageBox.Show("Wrong data input. Please provide valid data to add new manager."); return(null); } }
public ActionResult SaveBookingDetails(BookingViewModel objBookingViewModel) { if (ModelState.IsValid) { int NoOfdays = Convert.ToInt32((objBookingViewModel.BookingTo - objBookingViewModel.BookingFrom).TotalDays); Room objRoom = objHotelDBEntities.Rooms.Single(model => model.RoomId == objBookingViewModel.AssignRoomId); decimal RoomPrice = objRoom.RoomPrice; decimal TotalPrice = RoomPrice * NoOfdays; RoomBooking objRoomBooking = new RoomBooking() { CustomerName = objBookingViewModel.CustomerName, CustomerAddress = objBookingViewModel.CustomerAddress, BookingFrom = objBookingViewModel.BookingFrom, BookingTo = objBookingViewModel.BookingTo, AssignRoomId = objBookingViewModel.AssignRoomId, NoOfMembers = objBookingViewModel.NoOfMembers, TotalAmount = TotalPrice }; objHotelDBEntities.RoomBookings.Add(objRoomBooking); } objHotelDBEntities.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Delete(int id) { Message news = new Message(); if ((user)Session["user"] == null) { return RedirectToAction("Index", "Home"); } else { using (var db = new HotelDBEntities()) { try { reservation toDel = db.reservations.Find(id); db.reservations.Remove(toDel); db.SaveChanges(); news.type = 1; news.text = "Your reservation has been deleted"; return View("User", news); } catch (Exception e) { news.type = 0; news.text = "Unexpected database problem."; return View("User", news); } } } }
public ActionResult Registration([Bind(Exclude = "IsEmailVerified,ActivationCode")] Customer user) { bool Status = false; string message = ""; // // Model Validation if (ModelState.IsValid) { var isExist = IsAccountExist(user.Account_id); if (isExist) { ModelState.AddModelError("EmailExist", "Email already exist"); return(View(user)); } user.Password = Crypto.Hash(user.Password); user.ConfirmPassword = Crypto.Hash(user.ConfirmPassword); using (HotelDBEntities dc = new HotelDBEntities()) { dc.Customers.Add(user); dc.SaveChanges(); Status = true; } } else { message = "Invalid Request"; } ViewBag.Message = message; ViewBag.Status = Status; return(View(user)); }
public void Save(Hotel h) { HotelDBEntities ctx = new HotelDBEntities(); if (h.HotelId == 0) { ctx.Hotels.Add(h); ctx.SaveChanges(); } else { ctx.Hotels.Attach(h); ctx.Entry(h).State = System.Data.Entity.EntityState.Modified; ctx.SaveChanges(); } }
public Booking AddBooking(BookingViewModel bookingViewModel) { int numberOfDays = Convert.ToInt32((bookingViewModel.BookingTo - bookingViewModel.BookingFrom).TotalDays); Room room = dbContext.Rooms.SingleOrDefault(m => m.RoomId == bookingViewModel.AssignRoomId); decimal price = room.RoomPrice; decimal total = price * numberOfDays; var roomBooking = new Booking() { BookingFrom = bookingViewModel.BookingFrom, BookingTo = bookingViewModel.BookingTo, AssignRoomId = bookingViewModel.AssignRoomId, CustomerAddress = bookingViewModel.CustomerAddress, CustomerName = bookingViewModel.CustomerName, CustomerPhone = bookingViewModel.CustomerPhone, NoOfMembers = bookingViewModel.NoOfMembers, totalAmount = total, }; dbContext.Bookings.Add(roomBooking); room.BookingStatusId = 3; if (dbContext.SaveChanges() > 0) { return(roomBooking); } return(null); }
public void Save(Hotel h) { HotelDBEntities ctx = new HotelDBEntities(); if (h.HotelID == 0) {//neues Hotel einfügen ctx.Hotels.Add(h); ctx.SaveChanges(); } else {//bestehende Hotel aktualisieren ctx.Hotels.Attach(h); ctx.Entry(h).State = System.Data.Entity.EntityState.Modified; ctx.SaveChanges(); } }
public ActionResult deleteHotelRoom(int RoomID) { //string json = new System.IO.StreamReader(Request.InputStream).ReadToEnd(); //JObject jObject = JObject.Parse(json); //int RoomID = Convert.ToInt32(jObject["RoomID"] ?? 0); string msg = ""; using (HotelDBEntities db = new HotelDBEntities()) { HotelMaster room = db.HotelMasters.Where(a => a.RoomID == RoomID).FirstOrDefault(); if (room != null) { room.Flag = "D"; msg = "刪除完成!!"; db.SaveChanges(); } else { msg = "Error - 查無此ID!!"; } } //return Content(msg, "application/json"); //return new JsonResult { Data = new string[] { msg }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; return(Json(new string[] { msg }, JsonRequestBehavior.AllowGet)); }
// Method that update Employee public vwEmployee EditEmployee(vwEmployee employee) { try { using (HotelDBEntities context = new HotelDBEntities()) { tblUser userToEdit = (from ss in context.tblUsers where ss.UserId == employee.UserId select ss).First(); userToEdit.Name = employee.Name; userToEdit.Surname = employee.Surname; userToEdit.DateOfBirth = employee.DateOfBirth; userToEdit.Email = employee.Email; userToEdit.Username = employee.Username; userToEdit.Password = employee.Password; userToEdit.UserId = employee.UserId; tblUser userEdit = (from ss in context.tblUsers where ss.UserId == employee.UserId select ss).First(); context.SaveChanges(); tblEmployee employeeToEdit = (from ss in context.tblEmployees where ss.UserId == employee.UserId select ss).First(); employeeToEdit.Floor = employee.Floor; employeeToEdit.Gender = employee.Gender; employeeToEdit.Citizenship = employee.Citizenship; employeeToEdit.Responsability = employee.Responsability; employeeToEdit.Salary = employee.Salary; employeeToEdit.EmployeeID = employee.EmployeeID; tblEmployee employeeEdit = (from ss in context.tblEmployees where ss.EmployeeID == employee.EmployeeID select ss).First(); context.SaveChanges(); return(employee); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
public void Delete(Hotel h) { HotelDBEntities ctx = new HotelDBEntities(); ctx.Hotels.Attach(h); ctx.Entry(h).State = System.Data.Entity.EntityState.Deleted; ctx.Hotels.Remove(h); ctx.SaveChanges(); }
public void RemoveWorker(int id) { using (HotelDBEntities db = new HotelDBEntities()) { var res = db.Сотрудники.Where(x => x.ID_сотрудника == id).FirstOrDefault(); db.Сотрудники.Remove(res); db.SaveChanges(); } }
public void RemoveRoom(int id) { using (HotelDBEntities db = new HotelDBEntities()) { var res = db.Номера.Where(x => x.ID == id).FirstOrDefault(); db.Номера.Remove(res); db.SaveChanges(); } }
public Tipo_Habitacion actualizarTipo(string tipo, string descripcion, double tarifa) { Tipo_Habitacion habitacion = new Tipo_Habitacion(); try { habitacion.descripcion_Tipo_Habitacion = descripcion; habitacion.hotel_Tipo_Habitacion = "Patito"; habitacion.tarifa_Tipo_Habitacion = tarifa; habitacion.nombre_Tipo_Habitacion = tipo; db.Entry(habitacion).State = EntityState.Modified; db.SaveChanges(); return(db.Tipo_Habitacion.Find(tipo)); } catch (Exception ex) { return(habitacion); } }
private void createRoomType() { RoomType roomType = RoomType.CreateRoomType(0, "2", 300, "Deluxe"); using (HotelDBEntities hotelDBEntities = new HotelDBEntities()) { hotelDBEntities.RoomTypes.AddObject(roomType); hotelDBEntities.SaveChanges(); } }
public IHttpActionResult PostOrder(Order order) { try { //order table. if (order.OrderID == 0) { db.Orders.Add(order); } else { db.Entry(order).State = EntityState.Modified; } //order items table foreach (var item in order.OrderItems) { if (item.OrderItemID == 0) { db.OrderItems.Add(item); } else { db.Entry(item).State = EntityState.Modified; } } //delete for Order Items. foreach (var id in order.DeletedOrderItemIDs.Split(',').Where(x => x != "")) { OrderItem x = db.OrderItems.Find(Convert.ToInt64(id)); db.OrderItems.Remove(x); } db.SaveChanges(); return(Ok()); } catch (Exception ex) { throw ex; } }
public ActionResult Index(user user, string userBirth) { var userSession = (user)Session["user"]; user.email = userSession.email; DateTime newBirthDate = Convert.ToDateTime(userBirth); UserPanel modelPanel = new UserPanel(); using (var db = new HotelDBEntities()) { user currentUser = db.users.FirstOrDefault(u => u.email == user.email); if (String.IsNullOrEmpty(user.name) || String.IsNullOrEmpty(user.surname)) { modelPanel.user = currentUser; modelPanel.info.type = 0; modelPanel.info.text = "You didn't fill name or surname, please fill those fields."; return View(modelPanel); } if (!(String.IsNullOrEmpty(user.password)) && (user.password.Length > 10 || user.password.Length < 6)) { modelPanel.user = currentUser; modelPanel.info.type = 0; modelPanel.info.text = "Password must be between 6 and 10 characters."; return View(modelPanel); } if (!(String.IsNullOrEmpty(user.password)) && (user.password.Length < 10 || user.password.Length > 6)) { var crypto = new SimpleCrypto.PBKDF2(); var encrPass = crypto.Compute(user.password); currentUser.password = encrPass; currentUser.password_salt = crypto.Salt; } currentUser.name = user.name; currentUser.surname = user.surname; currentUser.country = user.country; currentUser.birth_date = newBirthDate; db.users.Attach(currentUser); db.Entry(currentUser).Property(p => p.password).IsModified = true; db.Entry(currentUser).Property(p => p.password_salt).IsModified = true; db.Entry(currentUser).Property(p => p.name).IsModified = true; db.Entry(currentUser).Property(p => p.surname).IsModified = true; db.Entry(currentUser).Property(p => p.country).IsModified = true; db.Entry(currentUser).Property(p => p.birth_date).IsModified = true; db.SaveChanges(); modelPanel.user = currentUser; modelPanel.info.type = 1; modelPanel.info.text = "Your data has been changed."; return View(modelPanel); } }
public ActionResult Book(string bookStart, string bookEnd, int bookRoom = 0) { var user = (user)Session["user"]; Message info = new Message(); if (user == null) { return RedirectToAction("Index", "Reservation"); } if (String.IsNullOrEmpty(bookStart) || String.IsNullOrEmpty(bookEnd) || bookRoom == 0) { info.text = "You have to choose room number and both dates."; return RedirectToAction("Index", "Reservation", new { info.text }); } DateTime startDate = Convert.ToDateTime(bookStart); DateTime endDate = Convert.ToDateTime(bookEnd); if (startDate >= endDate) { info.text = "Start day must be earlier ther end day."; return RedirectToAction("Index", "Reservation", new { info.text }); } List<DateTime> busyDates = new List<DateTime>(); using (var db = new HotelDBEntities()) { var reservs = db.reservations.ToList(); if (reservs.Count() == 0) { reservation res = new reservation(); res.start_date = startDate; res.end_date = endDate; res.room_id = bookRoom; res.user_id = user.id; res.days = Convert.ToInt32((endDate - startDate).TotalDays); db.reservations.Add(res); db.SaveChanges(); //---------------------------------------------------------------------------- info.type = 1; info.text = "Reservations has been added."; return RedirectToAction("Index", "Reservation", new { info.type, info.text }); } else { foreach (reservation item in reservs) { busyDates.Add(item.start_date); DateTime a = item.start_date; DateTime b = item.end_date; while (a.AddDays(1) != b) { busyDates.Add(a.AddDays(1)); a = a.AddDays(1); } } if (busyDates.Contains(startDate) || busyDates.Contains(endDate.AddDays(-1))) { info.type = 0; info.text = "Room is reserved in those days."; return RedirectToAction("Index", "Reservation", new { info.type, info.text }); } else { reservation res = new reservation(); res.start_date = startDate; res.end_date = endDate; res.room_id = bookRoom; res.user_id = user.id; res.days = Convert.ToInt32((endDate - startDate).TotalDays); db.reservations.Add(res); db.SaveChanges(); //---------------------------------------------------------------------------- info.type = 1; info.text = "Reservations has been added."; return RedirectToAction("Index", "Reservation", new { info.type, info.text }); } } } }
public ActionResult Forgot(string forgotEmail) { if (Session["user"] != null) { return RedirectToAction("Index", "Home"); } else { Message info = new Message(); if (String.IsNullOrEmpty(forgotEmail)) { info.type = 0; info.text = "You didn't fill the e-mail address field."; } else { using (var db = new HotelDBEntities()) { var user = db.users.FirstOrDefault(u => u.email == forgotEmail); if (user == null) { info.text = "User with such e-mail address doesn't exist."; } else { string newPass = "******"; var crypto = new SimpleCrypto.PBKDF2(); var encrPass = crypto.Compute(newPass); user.password = encrPass; user.password_salt = crypto.Salt; try { db.users.Attach(user); db.Entry(user).Property(p => p.password).IsModified = true; db.Entry(user).Property(p => p.password_salt).IsModified = true; db.SaveChanges(); info.type = 1; info.text = "Your password has been changed on: test123."; } catch (Exception e) { info.text = "Unexpected database error."; } } } } return View(info); } }
public ActionResult Register(string regEmail, string regPass, string regConfPass, string regName, string regSurname, string regCountry, string regBirth) { Message info = new Message(); List<bool> check = new List<bool>(); check.Add(String.IsNullOrEmpty(regEmail)); check.Add(String.IsNullOrEmpty(regPass) || regPass.Length < 6 || regPass.Length > 10); check.Add(String.IsNullOrEmpty(regConfPass) || regConfPass.Length < 6 || regConfPass.Length > 10); check.Add(String.Compare(regConfPass, regPass) != 0); check.Add(String.IsNullOrEmpty(regName)); check.Add(String.IsNullOrEmpty(regSurname)); check.Add(String.IsNullOrEmpty(regCountry)); check.Add(String.IsNullOrEmpty(regBirth)); if (check.Contains(true)) { info.text = "You didn't fill correctly all of the fields. "; info.text += "Remember that: password and confirmations must be the same, have between 6-10 marks and birth date of legal age."; info.type = 0; } else { user newUser = new user(); var crypto = new SimpleCrypto.PBKDF2(); var encrPass = crypto.Compute(regPass); newUser.password = encrPass; newUser.password_salt = crypto.Salt; DateTime birthDate = Convert.ToDateTime(regBirth); newUser.admin = false; newUser.birth_date = birthDate; newUser.email = regEmail; newUser.name = regName; newUser.surname = regSurname; newUser.country = regCountry; try { using (var db = new HotelDBEntities()) { var checkUser = db.users.FirstOrDefault(u => u.email == regEmail); if (checkUser == null) { db.users.Add(newUser); db.SaveChanges(); info.text = "New user has been added. Now you can log in using your e-mail and password."; info.type = 1; } else { info.text = "User with this e-mail address has been alredy created."; info.type = 0; } } } catch (Exception e) { info.text = "Unexpected database error. Please contact with administrator."; info.type = 0; } } return View(info); }