public async Task <ActionResult> ListingUpdate(int?id)
        {
            if (CacheHelper.Categories.Count == 0)
            {
                TempData[TempDataKeys.UserMessageAlertState] = "bg-danger";
                TempData[TempDataKeys.UserMessage]           = "[[[There are not categories available yet.]]]";
            }

            Listing item;

            var model = new ListingUpdateModel()
            {
                Categories = CacheHelper.Categories
            };

            if (id.HasValue)
            {
                item = await _listingService.FindAsync(id);

                if (item == null)
                {
                    return(new HttpNotFoundResult());
                }

                // Pictures
                var pictures = await _listingPictureservice.Query(x => x.ListingID == id).SelectAsync();

                var picturesModel = pictures.Select(x =>
                                                    new PictureModel()
                {
                    ID        = x.PictureID,
                    Url       = ImageHelper.GetListingImagePath(x.PictureID),
                    ListingID = x.ListingID,
                    Ordering  = x.Ordering
                }).OrderBy(x => x.Ordering).ToList();

                model.Pictures = picturesModel;
            }
            else
            {
                item = new Listing()
                {
                    CategoryID  = CacheHelper.Categories.Any() ? CacheHelper.Categories.FirstOrDefault().ID : 0,
                    Created     = DateTime.Now.Date,
                    LastUpdated = DateTime.Now.Date,
                    Expiration  = DateTime.Now.AddDays(30),
                    Enabled     = true,
                    Active      = true,
                }
            };

            // Item
            model.ListingItem = item;

            // Custom fields
            var customFieldCategoryQuery = await _customFieldCategoryService.Query(x => x.CategoryID == item.CategoryID).Include(x => x.MetaField.ListingMetas).SelectAsync();

            var customFieldCategories = customFieldCategoryQuery.ToList();
            var customFieldModel      = new CustomFieldListingModel()
            {
                ListingID      = item.ID,
                MetaCategories = customFieldCategories
            };

            model.CustomFields  = customFieldModel;
            model.Users         = UserManager.Users.ToList();
            model.UserID        = item.UserID;
            model.CategoryID    = item.CategoryID;
            model.ListingTypeID = item.ListingTypeID;

            // Listing types
            model.ListingTypes = CacheHelper.ListingTypes.Where(x => x.CategoryListingTypes.Any(y => y.CategoryID == model.CategoryID)).ToList();

            return(View(model));
        }
示例#2
0
        public async Task <ActionResult> ListingUpdate(int?id)
        {
            if (CacheHelper.Categories.Count == 0)
            {
                TempData[TempDataKeys.UserMessageAlertState] = "bg-danger";
                TempData[TempDataKeys.UserMessage]           = "[[[There are not categories available yet.]]]";
            }

            Listing listing;

            var userId = User.Identity.GetUserId();
            var user   = await UserManager.FindByIdAsync(userId);

            var model = new ListingUpdateModel()
            {
                Categories = CacheHelper.Categories
            };

            if (id.HasValue)
            {
                // return unauthorized if not authenticated
                if (!User.Identity.IsAuthenticated)
                {
                    return(new HttpUnauthorizedResult());
                }

                if (await NotMeListing(id.Value))
                {
                    return(new HttpUnauthorizedResult());
                }

                listing = await _listingService.FindAsync(id);

                if (listing == null)
                {
                    return(new HttpNotFoundResult());
                }

                // Pictures
                var pictures = await _listingPictureservice.Query(x => x.ListingID == id).SelectAsync();

                var picturesModel = pictures.Select(x =>
                                                    new PictureModel()
                {
                    ID        = x.PictureID,
                    Url       = ImageHelper.GetListingImagePath(x.PictureID),
                    ListingID = x.ListingID,
                    Ordering  = x.Ordering
                }).OrderBy(x => x.Ordering).ToList();

                model.Pictures = picturesModel;
            }
            else
            {
                listing = new Listing()
                {
                    CategoryID  = CacheHelper.Categories.Any() ? CacheHelper.Categories.FirstOrDefault().ID : 0,
                    Created     = DateTime.Now.Date,
                    LastUpdated = DateTime.Now.Date,
                    Expiration  = DateTime.MaxValue,
                    Enabled     = true,
                    Active      = true,
                };

                if (User.Identity.IsAuthenticated)
                {
                    listing.ContactEmail = user.Email;
                    listing.ContactName  = string.Format("{0} {1}", user.FirstName, user.LastName);
                    listing.ContactPhone = user.PhoneNumber;
                }
            }

            // Populate model with listing
            await PopulateListingUpdateModel(listing, model);

            return(View("~/Views/Listing/ListingUpdate.cshtml", model));
        }
        public ActionResult ListingCalendar(int id)
        {
            var userid    = User.Identity.GetUserId();
            var userlogin = UserManager.FindById(userid);

            var itemQuery = _listingService.Query(x => x.ID == id)
                            .Include(x => x.Category)
                            .Include(x => x.ListingMetas)
                            .Include(x => x.ListingMetas.Select(y => y.MetaField))
                            .Include(x => x.ListingStats)
                            .Include(x => x.ListingType)
                            .Include(x => x.Orders)
                            .Select();

            var item = itemQuery.FirstOrDefault();

            if (item == null)
            {
                return(new HttpNotFoundResult());
            }

            if (item.UserID != userid)
            {
                if (!User.IsInRole("Administrator"))
                {
                    return(new HttpNotFoundResult());
                }
            }

            var orders = _orderService.Queryable()
                         .Where(x => x.ListingID == id
                                //&& (x.Status != (int)Enum_OrderStatus.Pending || x.Status != (int)Enum_OrderStatus.Confirmed)
                                && (x.Status != (int)Enum_OrderStatus.Cancelled) &&
                                (x.FromDate.HasValue && x.ToDate.HasValue))
                         //&& (x.FromDate >= DateTime.Now || x.ToDate >= DateTime.Now))
                         .ToList();



            List <DateTime> datesBooked = new List <DateTime>();

            foreach (var order in orders)
            {
                for (DateTime date = order.FromDate.Value; date < order.ToDate.Value; date = date.Date.AddDays(1))
                {
                    datesBooked.Add(date);
                }
            }

            var pictures = _ListingPictureservice.Query(x => x.ListingID == id).Select();

            var picturesModel = pictures.Select(x =>
                                                new PictureModel()
            {
                ID        = x.PictureID,
                Url       = ImageHelper.GetListingImagePath(x.PictureID),
                ListingID = x.ListingID,
                Ordering  = x.Ordering
            }).OrderBy(x => x.Ordering).ToList();

            var reviews = _listingReviewService
                          .Query(x => x.UserTo == item.UserID)
                          .Include(x => x.AspNetUserFrom)
                          .Select();

            var user      = UserManager.FindById(item.UserID);
            var usuarios  = UserManager.Users.ToList();
            var itemModel = new ListingItemModel()
            {
                ListingCurrent = item,
                Pictures       = picturesModel,
                DatesBooked    = datesBooked,
                ListUsers      = usuarios.ToList(),
                ListingReviews = reviews.ToList(),
                ListOrder      = orders,
            };



            return(View(itemModel));
        }
        public async Task <ActionResult> ListingUpdate(int?id)
        {
            if (CacheHelper.Categories.Count == 0)
            {
                TempData[TempDataKeys.UserMessageAlertState] = "bg-danger";
                TempData[TempDataKeys.UserMessage]           = "[[[There are not categories available yet.]]]";
            }

            Listing item;

            var userId = User.Identity.GetUserId();
            var user   = await UserManager.FindByIdAsync(userId);

            var model = new ListingUpdateModel()
            {
                Categories = CacheHelper.Categories
            };

            if (id.HasValue)
            {
                // return unauthorized if not authenticated
                if (!User.Identity.IsAuthenticated)
                {
                    return(new HttpUnauthorizedResult());
                }

                if (await NotMeListing(id.Value))
                {
                    return(new HttpUnauthorizedResult());
                }

                item = await _listingService.FindAsync(id);

                if (item == null)
                {
                    return(new HttpNotFoundResult());
                }

                // Pictures
                var pictures = await _ListingPictureservice.Query(x => x.ListingID == id).SelectAsync();

                var picturesModel = pictures.Select(x =>
                                                    new PictureModel()
                {
                    ID        = x.PictureID,
                    Url       = ImageHelper.GetListingImagePath(x.PictureID),
                    ListingID = x.ListingID,
                    Ordering  = x.Ordering
                }).OrderBy(x => x.Ordering).ToList();

                model.Pictures = picturesModel;
            }
            else
            {
                item = new Listing()
                {
                    CategoryID   = CacheHelper.Categories.Any() ? CacheHelper.Categories.FirstOrDefault().ID : 0,
                    Created      = DateTime.Now.Date,
                    LastUpdated  = DateTime.Now.Date,
                    Expiration   = DateTime.MaxValue,
                    Enabled      = true,
                    Active       = true,
                    ContactEmail = user.Email,
                    ContactName  = string.Format("{0} {1}", user.FirstName, user.LastName),
                    ContactPhone = user.PhoneNumber
                };
            }

            // Item
            model.ListingItem = item;

            // Custom fields
            var customFieldCategoryQuery = await _customFieldCategoryService.Query(x => x.CategoryID == item.CategoryID).Include(x => x.MetaField.ListingMetas).SelectAsync();

            var customFieldCategories = customFieldCategoryQuery.ToList();
            var customFieldModel      = new CustomFieldListingModel()
            {
                ListingID      = item.ID,
                MetaCategories = customFieldCategories
            };

            model.CustomFields  = customFieldModel;
            model.UserID        = item.UserID;
            model.CategoryID    = item.CategoryID;
            model.ListingTypeID = item.ListingTypeID;

            // Listing types
            model.ListingTypes = CacheHelper.ListingTypes.Where(x => x.CategoryListingTypes.Any(y => y.CategoryID == model.CategoryID)).ToList();

            return(View("~/Views/Listing/ListingUpdate.cshtml", model));
        }
示例#5
0
        public async Task <ActionResult> Listing(int id)
        {
            var itemQuery = await _listingService.Query(x => x.ID == id)
                            .Include(x => x.Category)
                            .Include(x => x.ListingMetas)
                            .Include(x => x.ListingMetas.Select(y => y.MetaField))
                            .Include(x => x.ListingStats)
                            .Include(x => x.ListingType)
                            .SelectAsync();

            var item = itemQuery.FirstOrDefault();

            if (item == null)
            {
                return(new HttpNotFoundResult());
            }

            var orders = _orderService.Queryable()
                         .Where(x => x.ListingID == id
                                //&& (x.Status != (int)Enum_OrderStatus.Pending || x.Status != (int)Enum_OrderStatus.Confirmed)
                                && (x.Status != (int)Enum_OrderStatus.Cancelled) &&
                                (x.FromDate.HasValue && x.ToDate.HasValue) &&
                                (x.FromDate >= DateTime.Now || x.ToDate >= DateTime.Now))
                         .ToList();

            List <DateTime> datesBooked = new List <DateTime>();

            foreach (var order in orders)
            {
                for (DateTime date = order.FromDate.Value; date < order.ToDate.Value; date = date.Date.AddDays(1))
                {
                    datesBooked.Add(date);
                }
            }

            var pictures = await _listingPictureservice.Query(x => x.ListingID == id).SelectAsync();

            var camas = await _detailBedService.Query(x => x.ListingID == item.ID).Include(x => x.TypeOfBed).SelectAsync();

            var picturesModel = pictures.Select(x =>
                                                new PictureModel()
            {
                ID        = x.PictureID,
                Url       = ImageHelper.GetListingImagePath(x.PictureID),
                ListingID = x.ListingID,
                Ordering  = x.Ordering
            }).OrderBy(x => x.Ordering).ToList();

            var reviews = await _listingReviewService
                          .Query(x => x.UserTo == item.UserID)
                          .Include(x => x.AspNetUserFrom)
                          .SelectAsync();

            var user = await UserManager.FindByIdAsync(item.UserID);

            var itemModel = new ListingItemModel()
            {
                ListingCurrent = item,
                Pictures       = picturesModel,
                DatesBooked    = datesBooked,
                User           = user,
                ListingReviews = reviews.ToList(),
                ListBeds       = camas.ToList()
            };

            // Update stat count
            var itemStat = item.ListingStats.FirstOrDefault();

            if (itemStat == null)
            {
                _ListingStatservice.Insert(new ListingStat()
                {
                    ListingID   = id,
                    CountView   = 1,
                    Created     = DateTime.Now,
                    ObjectState = Repository.Pattern.Infrastructure.ObjectState.Added
                });
            }
            else
            {
                itemStat.CountView++;
                itemStat.ObjectState = Repository.Pattern.Infrastructure.ObjectState.Modified;
                _ListingStatservice.Update(itemStat);
            }

            await _unitOfWorkAsync.SaveChangesAsync();

            return(View("~/Views/Listing/Listing.cshtml", itemModel));
        }