Ejemplo n.º 1
0
        public IHttpActionResult ReserveRoomConfirmed([FromBody]ReserveConfirmationModel model)
        {
            string userEmail = User.Identity.Name;
            Room roomToReserve = db.Rooms.SingleOrDefault(x => x.RoomId == model.id);

            RoomAvailability roomToAddToAvailabilityDB = new RoomAvailability();

            roomToAddToAvailabilityDB.AccomodationId = roomToReserve.AccomodationId;
            roomToAddToAvailabilityDB.ArrivalDate = model.ArrivalDate;
            roomToAddToAvailabilityDB.DepartureDate = model.DepartureDate;
            roomToAddToAvailabilityDB.IsPaid = model.IsPaid;
            roomToAddToAvailabilityDB.RoomId = roomToReserve.RoomId;
            roomToAddToAvailabilityDB.TotalPrice = model.TotalPrice;
            roomToAddToAvailabilityDB.UserId = model.UserId;
            roomToAddToAvailabilityDB.UserEmail = userEmail;



            if (model.UserId == "unregistered")
            {
                return ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Please sign in or register in order to continue reservation process."));
            }
            else
            {
                BitBooking.DAL.Models.ApplicationUser userIdForCheck;
                try
                {
                    userIdForCheck = db.Users.First(x => x.Id == model.UserId);
                }
                catch
                {
                    return ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Please sign in or register in order to continue reservation process."));
                }
            }
            string temp = Convert.ToString(roomToAddToAvailabilityDB.AccomodationId);
            var data = new Message { AccomodationId = roomToAddToAvailabilityDB.AccomodationId, Content = "You have new reservation. Please check your panel", senderName = "New reservation", ReceiverId = temp, SentDate = DateTime.Now, Seen = false, ReceiverName = "System Message" };
            db.Messages.Add(data);

            db.RoomAvailabilities.Add(roomToAddToAvailabilityDB);
            db.SaveChanges();



            return Ok("You have sucessfully reserved a room!");
        }
        public ActionResult ReserveRoomConfirmed(int? id,DateTime ArrivalDate, DateTime DepartureDate, bool IsPaid, double TotalPrice, string UserId,double Price)
        {
            Room roomToReserve = db.Rooms.SingleOrDefault(x => x.RoomId == id);

            RoomAvailability roomToAddToAvailabilityDB = new RoomAvailability();

            roomToAddToAvailabilityDB.AccomodationId = roomToReserve.AccomodationId;
            roomToAddToAvailabilityDB.ArrivalDate = ArrivalDate;
            roomToAddToAvailabilityDB.DepartureDate = DepartureDate;
            roomToAddToAvailabilityDB.IsPaid = IsPaid;
            roomToAddToAvailabilityDB.RoomId = roomToReserve.RoomId;
            roomToAddToAvailabilityDB.TotalPrice = TotalPrice;
            roomToAddToAvailabilityDB.UserId = UserId;

            

            if (String.IsNullOrEmpty(UserId))
            {

                roomToReserve.TempArrivalDate = ArrivalDate;
                roomToReserve.TempDepartureDate = DepartureDate;
                roomToReserve.TempIsPaid = IsPaid;
                roomToReserve.TempTotalPrice = TotalPrice;
                roomToReserve.TempUserId = UserId;
                roomToReserve.Price = Price;
                ModelState.AddModelError("TempUserId", "You need to be registered user. Please register to reserve room and continue reservation process.");
                return View("ReserveRoom", roomToReserve);
            }
            else
            {
                ApplicationUser userIdForCheck;
                try
                {
                    userIdForCheck = db.Users.First(x => x.Id == UserId);
                }
                catch
                {
                    ModelState.AddModelError("TempUserId", "You need to be registered user. Please register to reserve room and continue reservation process.");
                    return View("ReserveRoom", roomToReserve);
                }
            }


            db.RoomAvailabilities.Add(roomToAddToAvailabilityDB);
            string temp = Convert.ToString(roomToAddToAvailabilityDB.AccomodationId);
            var data = new Message { AccomodationId = roomToAddToAvailabilityDB.AccomodationId, Content = "You have new reservation. Please check your panel", senderName = "New reservation", ReceiverId = temp, SentDate=DateTime.UtcNow, Seen=false, ReceiverName="System Message"};
            db.Messages.Add(data);
            db.SaveChanges();


            ViewBag.reservation = "You have successfully reserved room!";

            return RedirectToAction("Index", "Accomodations", new {reserved=1 });
        }
Ejemplo n.º 3
0
        public ActionResult Reply(Message message)
        {
            message.SentDate = DateTime.Now;
            var thisuser = User.Identity.GetUserId();

            db.Configuration.ProxyCreationEnabled = false;
            var userId = this.User.Identity.GetUserId();
            int? accID = db.Users.FirstOrDefault(x => x.Id == userId).AccomodationId;
            if (accID != 0)
            {
                message.SenderId = Convert.ToString(accID);
                message.senderName = db.Accomodations.Where(x => x.AccomodationId == accID).Select(x => x.AccomodationName).FirstOrDefault();
                message.ReceiverName = db.Users.Where(x => x.Id == message.ReceiverId).Select(x => x.UserName).FirstOrDefault();

            }
            else
            {
                int temp = Convert.ToInt32(message.ReceiverId);
                message.SenderId = thisuser;
                message.senderName = db.Users.Where(x => x.Id == thisuser).Select(x => x.UserName).FirstOrDefault();
                message.ReceiverName = db.Accomodations.Where(x => x.AccomodationId == temp).Select(x => x.AccomodationName).FirstOrDefault();
            
            
            
            };
            db.Messages.Add(message);
            db.SaveChanges();
           


            if (message == null)
            {
                return HttpNotFound();
            }
            
            return Json("Ok");
        }