Esempio n. 1
0
        public ActionResult DeclineReservedRoom(int room_id)
        {
            JongHorDBEntities1 jonghor = new JongHorDBEntities1();

            Room_Reserved roomReserved = jonghor.Room_Reserved.Where(r => r.Room_ID == room_id).First();

            jonghor.Room_Reserved.Remove(roomReserved);

            jonghor.Room.Find(room_id).Status = (int)Status.Avaliable;

            try
            {
                jonghor.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('New Dorm Added')</script>");

            return(Roomsort("All"));
        }
Esempio n. 2
0
        public void ResetReadMessage(string name)
        {
            JongHorDBEntities1 jonghor = new JongHorDBEntities1();

            foreach (var record in jonghor.Message.Where(m => m.Receiver_Username == name))
            {
                record.Isread = 1;
            }

            jonghor.SaveChanges();
        }
Esempio n. 3
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());
        }
Esempio n. 4
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);
            }
        }
Esempio n. 5
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);
            }
        }