示例#1
0
        public void SetUser(string name)
        {
            PersonBusinessLayer layer = new PersonBusinessLayer();

            user    = layer.GetUser(name);
            hasDorm = user.Dorm_ID != null;
            if (hasDorm)
            {
                isRoomMateMode = (Status)user.Find_Mate == Status.WaitRoomMate;
                var dormRate = user.Dorm_Rate.Where(u => u.Dorm_ID == user.Dorm_ID);
                if (dormRate.Count() > 0)
                {
                    rate = (int)dormRate.ToList <Dorm_Rate>()[0].Score;
                }
                else
                {
                    rate = 0;
                }
            }
            else
            {
                rate           = 0;
                isRoomMateMode = false;
            }
        }
示例#2
0
        public List <RoomViewModel> GetRoomListView(string userName)
        {
            //int RoomNo = 0;
            //List<string> PeopleNames = new List<string>();
            //string Status = "No";
            PersonBusinessLayer personBal = new PersonBusinessLayer();
            List <Person>       people    = personBal.GetPeople();
            int dormId = personBal.GetDormId(userName);

            List <int> roomNoList = new List <int>();
            RoomLayer  roomBal    = new RoomLayer();

            foreach (Room room in roomBal.GetRoom())
            {
                if (room.Dorm_ID == dormId)
                {
                    Rooms.Add(new RoomViewModel(room.Floor + room.Room_number, room.Person, room.Status, room.Room_ID));
                }
            }

            //foreach (int roomNo in roomNoList)
            //{
            //    foreach (Person person in people)
            //    {

            //        if(roomNo == person.roo)
            //    }
            //}

            return(Rooms);
        }
示例#3
0
        private void CheckDorm(string name)
        {
            PersonBusinessLayer layer = new PersonBusinessLayer();
            Person user = layer.GetUser(name);

            OwnDorm = user.Dorm.Count > 0;
        }
        public static PersonBusinessLayer FindPerson(int id)
        {
            PersonBusinessLayer person = null;

            using (SqlConnection con = new SqlConnection(ConnectionString()))
            {
                con.Open();
                using (SqlCommand cmd = new SqlCommand("SELECT ID, LastName, FirstName, Gender, DOB FROM Person WHERE ID = @NM", con))
                {
                    cmd.Parameters.AddWithValue("@NM", id);
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                           person = new PersonBusinessLayer();
                           person.ID = (int)reader["ID"];
                           person.LastName = (string)reader["LastName"];
                           person.FirstName = (string)reader["FirstName"];
                           person.Gender = (string)reader["Gender"];
                           person.DOB = (DateTime)reader["DOB"];
                        }
                    }
                }
            }
            return person;
        }
 public static bool AddPerson(PersonBusinessLayer person)
 {
     bool success = false;
     string cmdString = "INSERT INTO Person (LastName,FirstName,Gender,DOB) VALUES (@val1, @val2, @val3,@val4)";
     string connString = ConnectionString();
     using (SqlConnection conn = new SqlConnection(connString))
     {
         using (SqlCommand comm = new SqlCommand())
         {
             comm.Connection = conn;
             comm.CommandText = cmdString;
             comm.Parameters.AddWithValue("@val1", person.LastName);
             comm.Parameters.AddWithValue("@val2", person.FirstName);
             comm.Parameters.AddWithValue("@val3", person.Gender);
             comm.Parameters.AddWithValue("@val4", person.DOB);
             try
             {
                 conn.Open();
                 comm.ExecuteNonQuery();
                 success = true;
             }
             catch (SqlException e)
             {
                 throw new Exception(e.Message);
             }
         }
     }
     return success;
 }
示例#6
0
        public void SetRooms(string name)
        {
            PersonBusinessLayer pBal = new PersonBusinessLayer();
            Person user = pBal.GetUser(name);

            imageUrl = user.Dorm.First().Dorm_Picture.URL_Picture;
            roomListViewModel.GetRoomListView(name, Status.Reserved);
        }
示例#7
0
        public void GetRoomFilter(string name, Status status)
        {
            PersonBusinessLayer userBa = new PersonBusinessLayer();
            Person user = userBa.GetUser(name);

            foreach (var room in user.Dorm.First().Room)
            {
                if (room.Status == (int)status)
                {
                    Rooms.Add(new RoomViewModel(room.Floor + room.Room_number, room.Person, room.Status, room.Room_ID));
                }
            }
        }
示例#8
0
        public ActionResult FeedbackSubmit(string detail_feedback)
        {
            JongHorDBEntities1  db          = new JongHorDBEntities1();
            DormLayer           layer       = new DormLayer();
            PersonBusinessLayer personLayer = new PersonBusinessLayer();
            MessageLayer        memlayer    = new MessageLayer();
            List <Message>      mlist       = memlayer.GetMessage();
            int    mlistid = mlist.Count;
            Person user    = personLayer.GetUser(Session["UserName"].ToString());

            Message message = new Message();

            message.Receiver_Username = layer.GetDorm(user.Dorm_ID.Value).Person.Username;
            message.Sender_Username   = user.Username;
            message.MessageID         = mlistid + 1;
            message.Title             = "Feedback";
            Room room = user.Room;

            message.Text   = (room.Floor + "" + room.Room_ID) + ": " + detail_feedback;
            message.Isread = 0;
            message.Date   = DateTime.Now.ToString("dd-MM-yyyy") + " " +
                             DateTime.Today.ToString("HH:mm:ss tt"); //Date + Time

            db.Message.Add(message);
            try
            {
                db.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                // Retrieve the error messages as a list of strings.
                var errorMessages = ex.EntityValidationErrors
                                    .SelectMany(x => x.ValidationErrors)
                                    .Select(x => x.ErrorMessage);

                // Join the list to a single string.
                var fullErrorMessage = string.Join("; ", errorMessages);

                // Combine the original exception message with the new one.
                var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                // Throw a new DbEntityValidationException with the improved exception message.
                throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
            }

            Response.Write("<script>alert('Message has been sent')</script>");
            return(Index());
        }
示例#9
0
        public ActionResult StarCheck(int star)
        {
            JongHorDBEntities1 db = new JongHorDBEntities1();

            PersonBusinessLayer layer = new PersonBusinessLayer();
            Person user         = layer.GetUser(Session["UserName"].ToString());
            var    dormRate     = db.Dorm_Rate.Where(r => r.Person.Dorm_ID == user.Dorm_ID && r.Username == user.Username);
            bool   alreadyCheck = dormRate.Any();

            if (alreadyCheck)
            {
                Response.Write("<script>alert('You're already voted')</script>");
                return(Index());
            }
            else
            {
                Dorm_Rate rate = new Dorm_Rate();
                rate.Score    = star;
                rate.Text     = "";
                rate.Username = user.Username;
                rate.Dorm_ID  = user.Dorm_ID.Value;
                db.Dorm_Rate.Add(rate);
            }
            try
            {
                db.SaveChanges();
                return(Index());
            }
            catch (DbEntityValidationException ex)
            {
                // Retrieve the error messages as a list of strings.
                var errorMessages = ex.EntityValidationErrors
                                    .SelectMany(x => x.ValidationErrors)
                                    .Select(x => x.ErrorMessage);

                // Join the list to a single string.
                var fullErrorMessage = string.Join("; ", errorMessages);

                // Combine the original exception message with the new one.
                var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                // Throw a new DbEntityValidationException with the improved exception message.
                throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
            }
        }
示例#10
0
        private bool IsValid(string uname, string psw)
        {
            PersonBusinessLayer personBal = new PersonBusinessLayer();
            List <Person>       people    = personBal.GetPeople();

            foreach (Person person in people)
            {
                if (person.Username == uname)
                {
                    if (person.Password == psw)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            return(false);
        }
示例#11
0
        public ActionResult CreateUser(Person p)
        {
            PersonBusinessLayer bal = new PersonBusinessLayer();

            if (bal.IsValidUser(p))
            {
                ModelState.AddModelError("CredentialError", "Username is Exits");
                return(View("Register"));
            }
            else if (bal.IsValidSsn(p))
            {
                ModelState.AddModelError("CredentialError2", "SSN is Exits");
                return(View("Register"));
            }
            else
            {
                db.Person.Add(p);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
        }
示例#12
0
        public ActionResult SetRoommate(int roommate)
        {
            JongHorDBEntities1  db    = new JongHorDBEntities1();
            PersonBusinessLayer layer = new PersonBusinessLayer();
            Person user = layer.GetUser(Session["UserName"].ToString());

            if (roommate == 1)
            {
                db.Room.Where(r => r.Room_ID == user.Room_ID).First().Status      = (int)Status.WaitRoomMate;
                db.Person.Where(r => r.Room_ID == user.Room_ID).First().Find_Mate = (int)Status.WaitRoomMate;
            }
            else
            {
                db.Room.Where(r => r.Room_ID == user.Room_ID).First().Status      = (int)Status.NotAvaliable;
                db.Person.Where(r => r.Room_ID == user.Room_ID).First().Find_Mate = (int)Status.Avaliable;
            }
            try
            {
                db.SaveChanges();
                return(Index());
            }
            catch (DbEntityValidationException ex)
            {
                // Retrieve the error messages as a list of strings.
                var errorMessages = ex.EntityValidationErrors
                                    .SelectMany(x => x.ValidationErrors)
                                    .Select(x => x.ErrorMessage);

                // Join the list to a single string.
                var fullErrorMessage = string.Join("; ", errorMessages);

                // Combine the original exception message with the new one.
                var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                // Throw a new DbEntityValidationException with the improved exception message.
                throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
            }
        }
示例#13
0
        public void GetRoomListView(string name, Status status)
        {
            PersonBusinessLayer userBa = new PersonBusinessLayer();
            Person user = userBa.GetUser(name);

            int dorm_id = user.Dorm.First().Dorm_ID;

            foreach (var room in user.Dorm.First().Room)
            {
                if (room.Status == (int)Status.Reserved)
                {
                    Room_Reserved reserved = room.Room_Reserved.First();
                    if (reserved.Count <= reserved.Room.Room_Type.Max)
                    {
                        room.Person.Add(reserved.Person);
                        Rooms.Add(new RoomViewModel(room.Floor + room.Room_number, room.Person, room.Status, room.Room_ID));
                    }
                }
                else if (room.Status == (int)status)
                {
                    Rooms.Add(new RoomViewModel(room.Floor + room.Room_number, room.Person, room.Status, room.Room_ID));
                }
            }
        }
示例#14
0
 private void btnSearch_Click(object sender, EventArgs e)
 {
     if (!System.Text.RegularExpressions.Regex.IsMatch(txtSerch.Text, "^[0-9]*$") || string.IsNullOrEmpty(txtSerch.Text))
     {
         MessageBox.Show("Please enter a valid number");
     }
     else
     {
         PersonBusinessLayer personTobeUpdate = new PersonBusinessLayer();
         personTobeUpdate = PersonBusinessLayer.GetPerson(int.Parse(txtSerch.Text));
         if (personTobeUpdate == null)
         {
             MessageBox.Show("No records Found");
             ClearAll();
             ID = -1;
         }
         else
         {
             ID = personTobeUpdate.ID;
             txtFirst.Text = personTobeUpdate.FirstName;
             txtLst.Text = personTobeUpdate.LastName;
             cmbGender.SelectedItem = personTobeUpdate.Gender;
             dtpiker.Value = personTobeUpdate.DOB;
         }
     }
 }
示例#15
0
        public void SetUser(string name)
        {
            PersonBusinessLayer layer = new PersonBusinessLayer();

            user = layer.GetUser(name);
        }
 public static bool UpdatePerson(PersonBusinessLayer person)
 {
     bool success = false;
     string cmdString = "UPDATE Person SET LastName=@val1,FirstName= @val2, Gender=@val3,DOB=@val4 WHERE ID=@val0";
     string connString = ConnectionString();
     using (SqlConnection conn = new SqlConnection(connString))
     {
         using (SqlCommand comm = new SqlCommand())
         {
             comm.Connection = conn;
             comm.CommandText = cmdString;
             comm.Parameters.AddWithValue("@val0", person.ID);
             comm.Parameters.AddWithValue("@val1", person.LastName);
             comm.Parameters.AddWithValue("@val2", person.FirstName);
             comm.Parameters.AddWithValue("@val3", person.Gender);
             comm.Parameters.AddWithValue("@val4", person.DOB);
             try
             {
                 conn.Open();
                 comm.ExecuteNonQuery();
                 success = true;
             }
             catch (SqlException e)
             {
                 throw new Exception(e.Message);
             }
         }
     }
     return success;
 }