コード例 #1
0
 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);
             }
         }
     }
 }
コード例 #2
0
        /// <summary>
        /// Check room
        /// </summary>
        /// <param name="roomNo"></param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <returns></returns>
        public Boolean checkRoomAvailability(String roomNo, DateTime startDate, DateTime endDate)
        {
            Boolean isAvailable = true;
            List<RoomReservation> reservations = null;

            using (HotelDBEntities hotelDBEntities = new HotelDBEntities())
            {
                var result = hotelDBEntities.RoomReservations.Include("Room").Where(reservation => reservation.Room.RoomNo == roomNo);

                reservations = result.ToList();
            }

            if (reservations != null)
            {
                foreach (RoomReservation reservation in reservations)
                {
                    if (DateTime.Compare(reservation.StartDate, endDate) > 0 || DateTime.Compare(reservation.EndDate, startDate) < 0)
                    {

                        isAvailable = false;
                        break;
                    }
                }
            }

            return isAvailable;
        }
コード例 #3
0
        //
        // GET: /Room/

        public ActionResult Index()
        {
            using (var db = new HotelDBEntities())
            {
                List<room> rooms = new List<room>();
                rooms = db.rooms.ToList();
                if (rooms.Count() == 0)
                    return View();
                else
                    return View(rooms);
            }
        }
コード例 #4
0
        /// <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);
            }
        }
コード例 #5
0
 public ActionResult SaveData(RegisterTable objRegister)
 {
     if (ModelState.IsValid)
     {
         using (HotelDBEntities objHotelDBEntities = new HotelDBEntities())
         {
             objHotelDBEntities.RegisterTables.Add(objRegister);
             objHotelDBEntities.SaveChanges();
         }
         ModelState.Clear();
     }
     return(RedirectToAction("Index"));
 }
コード例 #6
0
ファイル: HomeController.cs プロジェクト: arsenitem/HotelWeb
 public ActionResult AddRoom(string room_type, string room_size, string room_price)
 {
     using (HotelDBEntities db = new HotelDBEntities())
     {
         Номера room = new Номера();
         room.Тип         = Convert.ToInt32(room_type);
         room.Вместимость = Convert.ToInt32(room_size);
         room.Цена        = Convert.ToDouble(room_price);
         db.Номера.Add(room);
         db.SaveChanges();
     }
     return(RedirectToAction("Rooms"));
 }
コード例 #7
0
        private void createReservation()
        {
            RoomReservation reservation = RoomReservation.CreateRoomReservation(0, DateTime.Today, DateTime.Today + new TimeSpan(3, 0, 0, 0), 2);

            reservation.Guest = createGuest();
            reservation.Room  = createRoom();

            using (HotelDBEntities hotelDBEntities = new HotelDBEntities())
            {
                hotelDBEntities.RoomReservations.AddObject(reservation);
                hotelDBEntities.SaveChanges();
            }
        }
コード例 #8
0
        private static Room createRoom()
        {
            Room room = Room.CreateRoom(0, "1002");

            room.RoomType = RoomType.CreateRoomType(0, "2", 600, "Executive");

            using (HotelDBEntities hotelDBEntities = new HotelDBEntities())
            {
                hotelDBEntities.Rooms.AddObject(room);
                hotelDBEntities.SaveChanges();
            }

            return(room);
        }
コード例 #9
0
 public ActionResult AddEmployee(string fio, string position, string phone)
 {
     using (HotelDBEntities db = new HotelDBEntities())
     {
         //var id = db.Должность.Where(x => x.Название == position).Select(x => x.ID_должности).FirstOrDefault();
         Сотрудники emp = new Сотрудники();
         emp.Имя          = fio;
         emp.Телефон      = phone;
         emp.ID_должности = Convert.ToInt32(position);
         db.Сотрудники.Add(emp);
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
コード例 #10
0
        /// <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);
            }
        }
コード例 #11
0
 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);
     }
 }
コード例 #12
0
 public vwManager FindManager(string username)
 {
     try
     {
         using (HotelDBEntities context = new HotelDBEntities())
         {
             vwManager admin = (from e in context.vwManagers where e.Username == username select e).First();
             return(admin);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }
コード例 #13
0
        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();
            }
        }
コード例 #14
0
        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();
            }
        }
コード例 #15
0
        public ActionResult getCust(string CustArea, int CustSeq)
        {
            List <vcustlist> vcust = new List <vcustlist>();

            using (HotelDBEntities db = new HotelDBEntities()) {
                vcust = db.vcustlists.Where(a => a.cust_area == CustArea && a.cust_seq == CustSeq).ToList();
                //foreach (var x in cust) {
                //    x.con_term = x.con_term.Value.ToLocalTime();
                //}
            }

            //return Json(cust, JsonRequestBehavior.AllowGet);
            return(new JsonResult {
                Data = vcust, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
コード例 #16
0
 /// <summary>
 /// get all users from database
 /// </summary>
 /// <returns></returns>
 public List <tblUser> GetAllUsers()
 {
     try
     {
         using (HotelDBEntities context = new HotelDBEntities())
         {
             List <tblUser> users = new List <tblUser>();
             users = context.tblUsers.ToList();
             return(users);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message.ToString());
         return(null);
     }
 }
コード例 #17
0
        // Method to get all floores where exists an Manager
        public List <string> GetManagerFloor()
        {
            try
            {
                using (HotelDBEntities context = new HotelDBEntities())
                {
                    List <string> floor = (from e in context.vwManagers select e.Floor).ToList();

                    return(floor);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
コード例 #18
0
        /// <summary>
        /// Get roorms
        /// </summary>
        /// <returns></returns>
        public List <Room> getAllRooms()
        {
            using (HotelDBEntities hotelDBEntities = new HotelDBEntities())
            {
                var query = from it in hotelDBEntities.Rooms.Include("RoomType")
                            where it.RoomType != null
                            select it;

                var list = query.ToList();
                foreach (var item in list)
                {
                    item.RoomTypeReference.Load();
                }

                return(list);
            }
        }
コード例 #19
0
 /// <summary>
 /// Gets all employees
 /// </summary>
 /// <returns>a list of found employees</returns>
 public List <tblEmployee> GetAllEmployees()
 {
     try
     {
         using (HotelDBEntities context = new HotelDBEntities())
         {
             List <tblEmployee> list = new List <tblEmployee>();
             list = (from x in context.tblEmployees select x).ToList();
             return(list);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }
コード例 #20
0
        public ActionResult modifyHotelRoom(int RoomID, string RoomNo, string RoomType, string Prize)
        {
            string msg = "";

            using (HotelDBEntities db = new HotelDBEntities()) {
                var r = db.HotelMasters.Where(a => a.RoomNo == RoomNo && a.RoomID != RoomID).FirstOrDefault();
                if (r != null)
                {
                    msg = "Error - 已有此房號!!";
                }
                else
                {
                    if (RoomID == 0)
                    {
                        //Insert
                        var Room = new HotelMaster();
                        Room.RoomNo   = RoomNo;
                        Room.RoomType = RoomType;
                        Room.Prize    = Prize.ToBig5();
                        Room.Flag     = "A";
                        db.HotelMasters.Add(Room);
                        msg = "新增完成!!";
                    }
                    else
                    {
                        //Update
                        var v = db.HotelMasters.Where(a => a.RoomID == RoomID).FirstOrDefault();
                        if (v != null)
                        {
                            v.RoomNo   = RoomNo;
                            v.RoomType = RoomType;
                            v.Prize    = Prize.ToBig5();
                            v.Flag     = "U";
                            msg        = "更新完成!!";
                        }
                        else
                        {
                            msg = "Error - 查無此ID!!";
                        }
                    }
                    db.SaveChanges();
                }
            }

            return(Json(new string[] { msg }, JsonRequestBehavior.AllowGet));
        }
コード例 #21
0
        public IEnumerable <ValueSet> getValueSets(string VLK_CODE)
        {
            if (VLK_CODE == null)
            {
                VLK_CODE = "";
            }
            List <ValueSet> valueSet = new List <ValueSet>();

            using (HotelDBEntities db = new HotelDBEntities()) {
                if (VLK_CODE != "")
                {
                    valueSet = db.ValueSets.Where(a => a.VLK_CODE == VLK_CODE && a.FLAG != "D").ToList();
                }
            }

            return(valueSet.AsEnumerable());
        }
コード例 #22
0
 public ActionResult Index()
 {
     if (Session["user"] == null)
     {
         return RedirectToAction("Index", "Home");
     }
     else
     {
         using (var db = new HotelDBEntities())
         {
             user userSession = (user)Session["user"];
             UserPanel modelPanel = new UserPanel();
             modelPanel.user = db.users.FirstOrDefault(u => u.email == userSession.email);
             return View(modelPanel);
         }
     }
 }
コード例 #23
0
        /// <summary>
        /// Get roorms
        /// </summary>
        /// <returns></returns>
        public List<Room> getAllRooms()
        {
            using (HotelDBEntities hotelDBEntities = new HotelDBEntities())
            {
                var query = from it in hotelDBEntities.Rooms.Include("RoomType")
                            where it.RoomType != null
                            select it;

                var list = query.ToList();
                foreach (var item in list)
                {
                    item.RoomTypeReference.Load();
                }

                return list;
            }
        }
コード例 #24
0
 /// <summary>
 /// Gets all information about managers
 /// </summary>
 /// <returns>a list of found managers</returns>
 public List <vwManager> GetAllManagersInfo()
 {
     try
     {
         using (HotelDBEntities context = new HotelDBEntities())
         {
             List <vwManager> list = new List <vwManager>();
             list = (from x in context.vwManagers select x).ToList();
             return(list);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }
コード例 #25
0
        // 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);
            }
        }
コード例 #26
0
 public RoomsList()
 {
     using (var db = new HotelDBEntities())
     {
         var prerooms = db.rooms.ToList();
         if (prerooms.Count() > 0) 
         {
             foreach (room item in prerooms) 
             {
                 SelectListItem selectItem = new SelectListItem();
                 selectItem.Value = Convert.ToString(item.id);
                 selectItem.Text = "Room #"+item.number+", Storey: "+item.floor+", ";
                 selectItem.Text += "Number of places: "+item.places;
                 rooms.Add(selectItem);
             }
         }
     }
 }
コード例 #27
0
        /// <summary>
        /// Get user id based on username
        /// </summary>
        /// <param name="username">Username</param>
        /// <returns>User id</returns>
        public int getUserId(string username)
        {
            try
            {
                using (HotelDBEntities context = new HotelDBEntities())
                {
                    tblUser user = context.tblUsers.FirstOrDefault(c => c.Username == username);

                    int id = user.UserID;
                    return(id);
                }
            }

            catch (Exception)
            {
                throw;
            }
        }
コード例 #28
0
        public ActionResult Login(login login, string ReturnUrl = "")
        {
            string message = "";

            using (HotelDBEntities dc = new HotelDBEntities())
            {
                var v = dc.Customers.Where(a => a.Account_id == login.Account_id).FirstOrDefault();
                if (v != null)
                {
                    if (string.Compare(Crypto.Hash(login.Password), v.Password) == 0)
                    {
                        int    timeout   = login.Remember ? 525600 : 20; // 525600 min = 1 year
                        var    ticket    = new FormsAuthenticationTicket(login.Account_id, login.Remember, timeout);
                        string encrypted = FormsAuthentication.Encrypt(ticket);
                        var    cookie    = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted);
                        cookie.Expires  = DateTime.Now.AddMinutes(timeout);
                        cookie.HttpOnly = true;
                        Response.Cookies.Add(cookie);


                        if (Url.IsLocalUrl(ReturnUrl))
                        {
                            return(Redirect(ReturnUrl));
                        }
                        else
                        {
                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                    else
                    {
                        message = "Invalid credential provided";
                    }
                }
                else
                {
                    message = "Invalid credential provided";
                }
            }
            ViewBag.Message = message;
            return(View());
        }
コード例 #29
0
ファイル: HomeController.cs プロジェクト: arsenitem/HotelWeb
        public ActionResult Find(string client_fio)
        {
            try
            {
                using (HotelDBEntities db = new HotelDBEntities())
                {
                    var guest_id = db.Клиенты.Where(x => x.ФИО == client_fio).Select(x => x.ID_клиента).FirstOrDefault();

                    var res = db.Учет.Where(x => x.ID_Клиента == guest_id).Select(x => x.ID_Номера).FirstOrDefault();
                    ViewBag.Res = true;
                    ViewBag.Num = res;
                    return(PartialView());
                }
            }
            catch
            {
                ViewBag.Res = false;
                return(PartialView());
            }
        }
コード例 #30
0
        protected void LoginUser_Click(object sender, EventArgs e)
        {
            var db = new HotelDBEntities();

            bool result = false;

            string firstName = FirstName.Text;
            string lastName  = LastName.Text;


            Session["firstname"] = firstName;
            Session["lastname"]  = lastName;


            Response.Write(Session["firstname"]);
            Response.Write(Session["lastname"]);



            foreach (customer c in AllCustomers())
            {
                if (c.firstName.ToLower().Equals(firstName.ToLower()) && c.lastName.ToLower().Equals(lastName.ToLower()))
                {
                    Session["id"] = c.customerID;
                    Response.Write(Session["id"]);

                    result = true;
                }
            }



            if (result)
            {
                Response.Redirect("UserEntryPage.aspx");
            }
            else
            {
                StatusMessage.Text = "ERROR!!!     Er du sikker på at du skrev riktig navn?";
            }
        }
コード例 #31
0
        protected void CreateUser_Click(object sender, EventArgs e)
        {
            // Default UserStore constructor uses the default connection string named: DefaultConnection



            var firstName = FirstName.Text;
            var lastName  = LastName.Text;


            var db = new HotelDBEntities();



            var id = AllCustomers()[AllCustomers().Count - 1].customerID + 1;

            customer cu = new customer(id, firstName, lastName);

            db.customer.Add(cu);
            db.SaveChanges();


            Session["id"]        = id;
            Session["firstname"] = firstName;
            Session["lastname"]  = lastName;

            Response.Write(Session["id"]);
            Response.Write(Session["firstname"]);
            Response.Write(Session["lastname"]);


            StatusMessage.Text = string.Format("User {0} {1} was created with id {2}!", firstName, lastName, id);



            MessageBox.Show(StatusMessage.Text);


            Response.Redirect("UserEntryPage.aspx");
        }
コード例 #32
0
        // GET: Employ
        public ActionResult Index()
        {
            HotelDBEntities db  = new HotelDBEntities();
            var             res = from Сотрудники in db.Сотрудники
                                  join Должность in db.Должность on Сотрудники.ID_должности equals Должность.ID_должности
                                  select new
            {
                emp_id      = Сотрудники.ID_сотрудника,
                emp_fio     = Сотрудники.Имя,
                emp_phone   = Сотрудники.Телефон,
                emp_positin = Должность.Название,
                emp_salary  = Должность.Оклад
            };
            List <string[]> emplist = new List <string[]>();

            foreach (var r in res)
            {
                emplist.Add(new string[] { r.emp_id.ToString(), r.emp_fio, r.emp_phone, r.emp_positin, r.emp_salary.ToString() });
            }

            return(View(emplist));
        }
コード例 #33
0
ファイル: HomeController.cs プロジェクト: arsenitem/HotelWeb
        public ActionResult Rooms()
        {
            List <string[]> roomslist = new List <string[]>();

            using (HotelDBEntities db = new HotelDBEntities())
            {
                var res = from Номера in db.Номера
                          join Категория_номера in db.Категория_номера on Номера.Тип equals Категория_номера.ID_типа
                          select new
                {
                    room_id    = Номера.ID,
                    room_type  = Категория_номера.Название,
                    room_size  = Номера.Вместимость,
                    room_price = Номера.Цена
                };
                foreach (var r in res)
                {
                    roomslist.Add(new string[] { r.room_id.ToString(), r.room_type, r.room_size.ToString(), r.room_price.ToString() });
                }
            }
            return(View(roomslist));
        }
コード例 #34
0
ファイル: HomeController.cs プロジェクト: arsenitem/HotelWeb
        public ActionResult NewOrder()
        {
            using (HotelDBEntities db = new HotelDBEntities())
            {
                var           rooms     = db.Номера.Select(x => x.ID);
                var           emp       = db.Сотрудники.Select(x => x.Имя);
                List <string> roomslist = new List <string>();
                List <string> emplist   = new List <string>();
                foreach (var r in rooms)
                {
                    roomslist.Add(r.ToString());
                }
                foreach (var r in emp)
                {
                    emplist.Add(r.ToString());
                }
                ViewBag.Rooms = roomslist;
                ViewBag.Emp   = emplist;
            }

            return(View());
        }
コード例 #35
0
        /// <summary>
        /// Deletes manager 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 DeleteUserManager(int userID)
        {
            try
            {
                using (HotelDBEntities context = new HotelDBEntities())
                {
                    bool isUser = IsUserID(userID);

                    // Deletes the manager
                    for (int i = 0; i < GetAllManagers().Count; i++)
                    {
                        if (GetAllManagers()[i].UserID == userID)
                        {
                            tblManager man = (from r in context.tblManagers where r.UserID == userID select r).First();
                            context.tblManagers.Remove(man);
                            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());
            }
        }
コード例 #36
0
        /// <summary>
        /// Search if user with that ID exists in the user table
        /// </summary>
        /// <param name="userID">Takes the user id that we want to search for</param>
        /// <returns>True if the user exists</returns>
        public bool IsUserID(int userID)
        {
            try
            {
                using (HotelDBEntities context = new HotelDBEntities())
                {
                    int result = (from x in context.tblUsers where x.UserID == userID select x.UserID).FirstOrDefault();

                    if (result != 0)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception " + ex.Message.ToString());
                return(false);
            }
        }
コード例 #37
0
 // Method that reads all Managers from database
 public List <vwManager> GetAllManagers()
 {
     try
     {
         using (HotelDBEntities context = new HotelDBEntities())
         {
             List <vwManager> list = new List <vwManager>();
             list = (from x in context.vwManagers select x).ToList();
             //for (int i = 0; i < list.Count; i++)
             //{
             //    if (list[i].Stored == true)
             //    {
             //        Capacity += list[i].Quantity;
             //    }
             //}
             return(list);
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }
コード例 #38
0
 public ActionResult Login(string logEmail, string logPass)
 {
     var sessioUser = (user)Session["user"];
     if (sessioUser != null)
     {
         return RedirectToAction("Index", "Home");
     }
     else
     {
         Message info = new Message();
         List<bool> check = new List<bool>();
         check.Add(String.IsNullOrEmpty(logEmail));
         check.Add(String.IsNullOrEmpty(logPass) || logPass.Length < 6 || logPass.Length > 10);
         if (check.Contains(true))
         {
             info.text = "You didn't fill correctly all of the fields. ";
             info.text += "Remember that: password must have between 6-10 marks.";
             info.type = 0;
         }
         else
         {
             try
             {
                 using (var db = new HotelDBEntities())
                 {
                     var checkUser = db.users.FirstOrDefault(u => u.email == logEmail);
                     if (checkUser == null)
                     {
                         info.text = "You have typed wrong e-mail or password.";
                         info.type = 0;
                     }
                     else
                     {
                         var crypto = new SimpleCrypto.PBKDF2();
                         var encrPass = crypto.Compute(logPass, checkUser.password_salt);
                         if (encrPass == checkUser.password)
                         {
                             Session["user"] = checkUser;
                             return RedirectToAction("Index", "Home");
                         }
                         else
                         {
                             info.text = "You have typed wrong e-mail or password.";
                             info.type = 0;
                         }
                     }
                 }
             }
             catch (Exception e)
             {
                 info.text = "Unexpected database error. Please contact with administrator.";
                 info.type = 0;
             }
         }
         return RedirectToAction("Index", "Home", new { info.type, info.text });
     }
 }
コード例 #39
0
 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 });
             }
         }
     }
 }
コード例 #40
0
 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);
 }
コード例 #41
0
 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);
     }
 }