public NewsModel()
 {
     using (var db=new DatabaseModel())
     {
         Articles = db.article.OrderByDescending(a=>a.AddedDateTime).ToList();
     }
 }
Ejemplo n.º 2
0
 public ReserveModel()
 {
     using (var db=new DatabaseModel())
     {
         Beds = db.bed.ToList();
         Rooms = db.room.ToList();
     }
     
 }
 public HeaderAuthPartialModel(string email)
 {
     using (var db = new DatabaseModel())
     {
         int clientId = db.client.First(cl => cl.Email == email).Id;
         var client=db.client.First(c => c.Id == clientId);
         Email = client.Email;
         FirstName = client.FirstName;
     }
 }
 public ActionResult Article(int id)
 {
     using (var db = new DatabaseModel())
     {
         List<article> model = new List<article>
         {
             db.article.FirstOrDefault(a => a.Id == id)
         };
         return View(model);
     }
 }
 public ActionResult About()
 {
     using (var db = new DatabaseModel())
     {
         List<article> model = new List<article>
         {
             db.article.FirstOrDefault(a => a.Alias == "About")
         };
         return View("Article", model);
     }
 }
 private ActionResult Article(string alias)
 {
     using (var db = new DatabaseModel())
     {
         List<article> model = new List<article>
         {
             db.article.FirstOrDefault(a => a.Alias == alias)
         };
         return View(model);
     }
 }
Ejemplo n.º 7
0
 public MyOrderModel(order_room orderRoom)
 {
     StartDate = orderRoom.StartDate;
     EndDate = orderRoom.EndDate;
     using (var db = new DatabaseModel())
     {
         var room = db.room.First(r => r.Id == orderRoom.RoomId);
         RoomNumber = room.Number;
         Floor = room.Floor;
     }
     _type = "room";
 }
Ejemplo n.º 8
0
 public IndexModel()
 {
     using (var db = new DatabaseModel())
     {
         Comments = db.comment.ToList();
         Comments = Comments.Select(c =>
         {
             if (c.ClientId != null)
                 c.Name = c.client.FirstName;
             return c;
         }).ToList();
     }
 }
Ejemplo n.º 9
0
        public MyOrderModel(order_bed orderBed)
        {
            StartDate = orderBed.StartDate;
            EndDate = orderBed.EndDate;
            using (var db = new DatabaseModel())
            {
                var bed = db.bed.First(r => r.Id == orderBed.BedId);
                var room = db.room.First(r => r.Id == bed.RoomId);
                RoomNumber = room.Number;
                Floor = room.Floor;
            }
            _type = "bed";

        }
Ejemplo n.º 10
0
        public static string Authorize(string password, string email)
        {
            using (var db = new DatabaseModel())
            {
                var client =
                    db.client.FirstOrDefault(c => c.Email == email && c.Password == password);

                bool clientExists = client != null;
                if (!clientExists)
                    return "notFound";
                var identity = new GenericIdentity(client.Email);
                HttpContext.Current.User = new GenericPrincipal(identity, new[] {"client"});
                FormsAuthentication.SetAuthCookie(client.Email, false);
                return "";

            }
        }
Ejemplo n.º 11
0
 public static string Register(client client)
 {
     string result;
     using (var db = new DatabaseModel())
     {
         if (db.client.Any(c => c.Email.ToLower() == client.Email.ToLower()))
         {
             result = "userExists";
         }
         else
         {
             db.client.Add(client);
             db.SaveChanges();
             result = "";
         }
     }
     return result;
 }
        public ActionResult ReserveBed(int[] bedsId, string startDate, string endDate)
        {
            JsonResult result;

            if (AuthProvider.IsAuthorized)
            {
                int clientId = AuthProvider.ClientId;
                DateTime startDateTime = DateTime.Parse(startDate);
                DateTime endDateTime = DateTime.Parse(endDate);
                int daysCount = (endDateTime - startDateTime).Days;
                using (var db = new DatabaseModel())
                {
                    var trans = db.Database.BeginTransaction();
                    try
                    {
                        var beds = db.bed.Where(r => bedsId.Contains(r.Id)).ToList();
                        check check = new check
                        {
                            ClientId = clientId,
                            CreatedDate = DateTime.Now,
                            Sum = beds.Sum(r => r.Price*daysCount),
                            Pawn=0
                        };
                        db.check.Add(check);
                        db.SaveChanges();
                        foreach (var id in bedsId)
                        {
                            db.order_bed.Add(new order_bed
                            {
                                ClientId = db.client.First(cl => cl.Email == HttpContext.User.Identity.Name).Id,
                                StartDate = startDateTime,
                                EndDate = endDateTime,
                                BedId = id,
                                CheckId = check.Id
                            });
                        }
                        db.SaveChanges();
                        trans.Commit();

                        result = new JsonResult
                        {
                            JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                            Data = new
                            {
                                success = true
                            }
                        };
                    }
                    catch (Exception e)
                    {
                        trans.Rollback();
                        result = new JsonResult
                        {
                            JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                            Data = new
                            {
                                success = false,
                                errorReason = "unknown"
                            }
                        };
                    }
                    return result;
                }
            }
            result = new JsonResult
            {
                JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                Data = new
                {
                    success = false,
                    errorReason = "notAuthorized",
                    html = PartialView("_AuthModalPartial").RenderToString()
                }
            };
            return result;
        }
        public ActionResult FindBedInDateRange(string startDate,string endDate)
        {
            try
            {
                DateTime startDateTime = DateTime.Parse(startDate);
                DateTime endDateTime = DateTime.Parse(endDate);
                using (var db = new DatabaseModel())
                {
                    var ordersRoom = (
                        from orderRoom in db.order_room

                        where
                             (((orderRoom.StartDate <= startDateTime) && (startDateTime < orderRoom.EndDate)) ||
                               ((orderRoom.StartDate < endDateTime) && (endDateTime <= orderRoom.EndDate)))
                        select orderRoom).ToList();

                    var ordersBed = (
                        from orderBed in db.order_bed
                        where
                             (((orderBed.StartDate <= startDateTime) && (startDateTime < orderBed.EndDate)) ||
                               ((orderBed.StartDate < endDateTime) && (endDateTime <= orderBed.EndDate)))
                        select orderBed).ToList();

                    var orderBedIds = ordersBed.Select(ob => ob.BedId).ToList();
                    var orderRoomIds = ordersRoom.Select(or => or.RoomId).ToList();

                    var freeBeds = (
                        from b in db.bed
                        where
                            ((!orderBedIds.Contains(b.Id)) &&
                             (!orderRoomIds.Contains(b.RoomId)))
                        select b
                        ).ToList();


                    var rooms = db.room.ToList();
                    var model = new ReserveModel
                    {
                        Rooms = rooms,
                        Beds = freeBeds
                    };
                    return new JsonResult
                    {
                        Data = new
                        {
                            success = true,
                            html = PartialView("_FoundBedPartial", model).RenderToString()
                        }
                    };
                }
            }
            catch (Exception e)
            {
                return new JsonResult
                {
                    Data = new
                    {
                        success = false                    
                    }
                };
            }
        }
        public ActionResult FindRoomInDateRange(string startDate, string endDate)
        {
            try
            {
                DateTime startDateTime = DateTime.Parse(startDate);
                DateTime endDateTime = DateTime.Parse(endDate);
                using (var db = new DatabaseModel())
                {
                    var ordersRoom = (
                        from orderRoom in db.order_room
                        where
                            (((orderRoom.StartDate <= startDateTime) && (startDateTime < orderRoom.EndDate)) ||
                             ((orderRoom.StartDate < endDateTime) && (endDateTime <= orderRoom.EndDate)))
                        select orderRoom);

                    var ordersBed = (
                        from orderBed in db.order_bed
                        where
                            (((orderBed.StartDate <= startDateTime) && (startDateTime < orderBed.EndDate)) ||
                             ((orderBed.StartDate < endDateTime) && (endDateTime <= orderBed.EndDate)))
                        select orderBed);

                    List<int> reservedRooms =
                        ordersRoom.Select(or => or.RoomId)
                            .Union(db.bed.Where(b => ordersBed.Any(ob => ob.BedId == b.Id)).Select(b => b.RoomId))
                            .ToList();
                        
                        /*(from orderBed in ordersBed
                        from orderRoom in ordersRoom
                        from bed in db.bed
                        from room in db.room
                        where
                            (((bed.RoomId == room.Id) &&
                              (orderBed.BedId == bed.Id)) ||
                             (orderRoom.RoomId == room.Id))
                        select room.Id
                        ).ToList();*/
                    var rooms = db.room.Where(r => !reservedRooms.Contains(r.Id)).ToList();

                    var beds = (from r in rooms
                        from b in db.bed
                        where (b.RoomId == r.Id)
                        select b
                        ).Distinct().ToList();

                    var model = new ReserveModel
                    {
                        Rooms = rooms,
                        Beds = beds
                    };
                    return new JsonResult
                    {
                        Data = new
                        {
                            success = true,
                            html = PartialView("_FoundRoomPartial", model).RenderToString()
                        }
                    };
                }
            }
            catch (Exception e)
            {
                return new JsonResult
                {
                    Data = new
                    {
                        success = false                   
                    }
                };
            }
        }
Ejemplo n.º 15
0
        public SimpleReserveModel(string type, int personsCount, DateTime inDate, DateTime outDate)
        {
            if(inDate>outDate)
                throw new Exception("Некорректно указаны даты");
            if(type.IsNullOrWhiteSpace())
                throw new Exception("Некорректные данные");
            using (var db = new DatabaseModel())
            {
                Type = type == "room" ? ReserveType.Room : ReserveType.Bed;
                if (Type == ReserveType.Room)
                {
                    var ordersRoom = (
                        from orderRoom in db.order_room
                        where
                            (((orderRoom.StartDate <= inDate) && (inDate < orderRoom.EndDate)) ||
                             ((orderRoom.StartDate < outDate) && (outDate <= orderRoom.EndDate)))
                        select orderRoom);

                    var ordersBed = (
                        from orderBed in db.order_bed
                        where
                            (((orderBed.StartDate <= inDate) && (inDate < orderBed.EndDate)) ||
                             ((orderBed.StartDate < outDate) && (outDate <= orderBed.EndDate)))
                        select orderBed);

                    List<int> reservedRooms =
                        ordersRoom.Select(or => or.RoomId)
                            .Union(db.bed.Where(b => ordersBed.Any(ob => ob.BedId == b.Id)).Select(b => b.RoomId))
                            .ToList();
                    Rooms =
                        db.room.Where(r => (!reservedRooms.Contains(r.Id)) && (r.bed.Count >= personsCount)).ToList();
                    Beds = db.bed.ToList();
                }
                else
                {
                    var ordersRoom = (
                        from orderRoom in db.order_room

                        where
                             (((orderRoom.StartDate <= inDate) && (inDate < orderRoom.EndDate)) ||
                               ((orderRoom.StartDate < outDate) && (outDate <= orderRoom.EndDate)))
                        select orderRoom).ToList();

                    var ordersBed = (
                        from orderBed in db.order_bed
                        where
                             (((orderBed.StartDate <= inDate) && (inDate < orderBed.EndDate)) ||
                               ((orderBed.StartDate < outDate) && (outDate <= orderBed.EndDate)))
                        select orderBed).ToList();

                    var orderBedIds = ordersBed.Select(ob => ob.BedId).ToList();
                    var orderRoomIds = ordersRoom.Select(or => or.RoomId).ToList();

                    Beds = (
                        from b in db.bed
                        where
                            ((!orderBedIds.Contains(b.Id)) &&
                             (!orderRoomIds.Contains(b.RoomId)))
                        select b
                        ).ToList();
                    Rooms = db.room.ToList();
                }
                OutDate = outDate;
                InDate = inDate;
            }
        }
Ejemplo n.º 16
0
 public ActionResult MyOrders()
 {
     if (!AuthProvider.IsAuthorized)
     {
         RedirectToAction("Index", "Home");
     }
     var model = new List<MyOrderModel>();
     using (var db=new DatabaseModel())
     {
         foreach (var order in db.order_bed.Where(ob => ob.ClientId == AuthProvider.ClientId))
         {
             model.Add(new MyOrderModel(order));
         }
         foreach (var order in db.order_room.Where(ob => ob.ClientId == AuthProvider.ClientId))
         {
             model.Add(new MyOrderModel(order));
         }
     }
     return View(model);
 }
Ejemplo n.º 17
0
 public ActionResult AddComment(CommentModel model)
 {
     if((!AuthProvider.IsAuthorized)&&model.Name.IsNullOrWhiteSpace())
         throw new Exception("Не удалось добавить комментарий");
     using (var db=new DatabaseModel())
     {
         db.comment.Add(new comment
         {
             ClientId = AuthProvider.IsAuthorized ? (int?) AuthProvider.ClientId : null,
             Name = model.Name,
             Text = model.Message
         });
         db.SaveChanges();
     }
     return new JsonResult{Data = true, JsonRequestBehavior = JsonRequestBehavior.DenyGet};
 }