Beispiel #1
0
        public string GetJsonAnalyticParameters(int deviceId)
        {
            RootRepository.SecurityRepository.AssertDeviceAuthorization(deviceId);
            var device = RootRepository.DeviceRepository.GetDevice(deviceId);

            var requestCategories =
                Rp.ExecuteAction(
                    () =>
                    ProxylessContext.RequestCategories.Where(x => x.FKHotel == device.FKHotel)
                    .OrderBy(x => x.Ordinal)
                    .Select(
                        x =>
                        new { x.PKID, x.Name })).Distinct().OrderBy(x => x.Name).ToArray();

            var requestTypes =
                Rp.ExecuteAction(
                    () =>
                    ProxylessContext.RequestTypes.Where(x => x.FKHotel == device.FKHotel)
                    .OrderBy(x => x.Ordinal)
                    .Select(x => new { x.PKID, x.Name, x.FKRequestCategory })).Distinct().OrderBy(x => x.Name).ToArray();

            var requestUsers =
                Rp.ExecuteAction(
                    () =>
                    ProxylessContext.RequestGroups.Where(x => x.FKHotel == device.FKHotel)
                    .SelectMany(x => x.RequestGroupUserMaps.Select(y => new { y.RequestUser.PKID, y.RequestUser.Name })))
                .Distinct().OrderBy(x => x.Name)
                .ToArray();

            return(new { RequestCategories = requestCategories, RequestTypes = requestTypes, RequestUsers = requestUsers, PKID = deviceId }.ToJSON());
        }
Beispiel #2
0
        public void UpdateCategory(int deviceId, CategoryModel category)
        {
            if (category != null)
            {
                RootRepository.SecurityRepository.AssertDevicePermissions(deviceId);

                Rp.ExecuteAction(() =>
                {
                    CategoryMap categoryMap = (from cm in Context.CategoryMaps.Where(cm2 => cm2.IsActive)
                                               where cm.FKChildCategory == category.PKID &&
                                               cm.FKParentCategory == null
                                               select cm).FirstOrDefault();

                    if (categoryMap != null)
                    {
                        HotelCategoryMap hotelCategoryMap = (from hcm in Context.HotelCategoryMaps.Where(hcm2 => hcm2.IsActive)
                                                             where hcm.FKDevice == deviceId &&
                                                             hcm.FKCategoryMap == categoryMap.PKID
                                                             select hcm).FirstOrDefault();

                        if (hotelCategoryMap != null)
                        {
                            hotelCategoryMap.FKImage = category.Image.PKID;

                            Context.LogValidationFailSaveChanges(RootRepository.SecurityRepository.AuditLogUserId);
                        }
                    }
                });
            }
        }
Beispiel #3
0
        private void InsertTip(int deviceId, int userId, string tip, int?amenityId = null, int?enterpriseId = null, int?enterpriseLocationId = null)
        {
            Rp.ExecuteAction(() =>
            {
                int?hotelId = Rp.ExecuteAction(() => (from d in Context.Devices.Where(d2 => d2.DeviceDetail.IsActive)
                                                      where d.PKID == deviceId
                                                      select d.FKHotel)).FirstOrDefault();

                if (hotelId.HasValue)
                {
                    var now = DateTime.Now;

                    var insiderTip = new InsiderTip()
                    {
                        FKAmenity            = amenityId,
                        FKContactUser        = userId,
                        FKEnterprise         = enterpriseId,
                        FKEnterpriseLocation = enterpriseLocationId,
                        FKHotel = hotelId,
                        LastModifiedDateTime      = now,
                        FKLastModifiedContactUser = userId,
                        Tip         = tip,
                        TipDateTime = now
                    };

                    Context.InsiderTips.AddObject(insiderTip);
                }
            });
        }
Beispiel #4
0
        public void InsertEnterpriseLocationBlacklist(int deviceId, int enterpriseLocationId)
        {
            RootRepository.SecurityRepository.AssertDevicePermissions(deviceId);

            var enterpriseId = Rp.ExecuteAction(() => (from el in Context.EnterpriseLocations
                                                       where el.PKID == enterpriseLocationId
                                                       select el.FKEnterprise)).FirstOrDefault();

            DeleteEnterpriseLocationRecommend(deviceId, enterpriseId, enterpriseLocationId);

            Rp.ExecuteAction(() =>
            {
                var hotelId = (from d in Context.Devices.Where(d2 => d2.DeviceDetail.IsActive)
                               where d.PKID == deviceId
                               select d.FKHotel).FirstOrDefault();

                var blacklistEnterpriseLocationMap = new BlackListEnterpriseLocationMap
                {
                    FKEnterpriseLocation = enterpriseLocationId,
                    FKHotel = hotelId
                };

                Context.BlackListEnterpriseLocationMaps.AddObject(blacklistEnterpriseLocationMap);
                Context.LogValidationFailSaveChanges(RootRepository.SecurityRepository.AuditLogUserId);
            });
        }
Beispiel #5
0
        public HotelModel GetHotelFromDevice(int deviceId)
        {
            RootRepository.SecurityRepository.AssertDevicePermissions(deviceId);

            var hotel = Rp.ExecuteAction(() => (from h in Context.Hotels
                                                let hd = h.HotelDetail
                                                         where h.Devices.Select(d => d.PKID).Contains(deviceId)
                                                         select new HotelModel
            {
                Location = new LocationModel
                {
                    Address = hd.Address,
                    City = hd.City,
                    ISOCountryCode = hd.ISOCountryCode,
                    Latitude = h.HotelDetail.Latitude,
                    Longitude = h.HotelDetail.Longitude,
                    PostalCode = hd.Zip,
                    ISOStateCode = hd.State,
                },
                Name = h.Name,
                PKID = h.PKID,
                RadiusInMiles = h.HotelDetail.Radius
            }).FirstOrDefault());

            return(hotel);
        }
Beispiel #6
0
        public void UpdateCategories(int deviceId, List <int> addCategoryIds, List <int> removeCategoryIds)
        {
            if (addCategoryIds != null || removeCategoryIds != null)
            {
                RootRepository.SecurityRepository.AssertDevicePermissions(deviceId);

                if (addCategoryIds != null)
                {
                    Rp.ExecuteAction(() =>
                    {
                        addCategoryIds.ForEach(id => Context.HotelCategoryMaps.Add(new HotelCategoryMap()
                        {
                            CategoryMap = Context.CategoryMaps.FirstOrDefault(cm => cm.FKChildCategory == id && cm.FKParentCategory == null),
                            FKDevice    = deviceId
                        }));

                        Context.LogValidationFailSaveChanges(RootRepository.SecurityRepository.AuditLogUserId);
                    });
                }

                if (removeCategoryIds != null)
                {
                    DeleteHotelCategories(deviceId, removeCategoryIds);
                }
            }
        }
Beispiel #7
0
        public void UpdateCategories(int deviceId, List <CategoryModel> categories)
        {
            if (categories != null)
            {
                RootRepository.SecurityRepository.AssertDevicePermissions(deviceId);

                Rp.ExecuteAction(() =>
                {
                    HotelCategoryMap hotelCategoryMap;

                    foreach (var category in categories)
                    {
                        hotelCategoryMap = (from hcm in Context.HotelCategoryMaps.Where(hcm2 => hcm2.IsActive == null || hcm2.IsActive)
                                            let cm = hcm.CategoryMap
                                                     let c = cm.ChildCategory
                                                             where hcm.FKDevice == deviceId &&
                                                             c != null &&
                                                             c.PKID == category.PKID
                                                             select hcm).FirstOrDefault();

                        if (hotelCategoryMap != null)
                        {
                            hotelCategoryMap.Ordinal = category.Order;
                        }
                    }

                    Context.LogValidationFailSaveChanges(RootRepository.SecurityRepository.AuditLogUserId);
                });
            }
        }
Beispiel #8
0
        private void UpdateEnterprise(EnterpriseModel enterprise)
        {
            var culture        = MvcApplication.GetCurrentCulture();
            var nativeLanguage = Monscierge.Utilities.Translation.GetLanguageFromCulture(culture);

            if (enterprise != null)
            {
                Rp.ExecuteAction(() =>
                {
                    var dbEnterprise = (from e in ProxylessContext.Enterprises.Where(e2 => e2.IsActive)
                                        where e.PKID == enterprise.PKID
                                        select e).FirstOrDefault();

                    if (dbEnterprise != null)
                    {
                        if (dbEnterprise.DescriptionLanguage.Equals(nativeLanguage, StringComparison.InvariantCultureIgnoreCase))
                        {
                            dbEnterprise.Description = enterprise.Description;
                        }
                        else
                        {
                            dbEnterprise.LocalizedDescription =
                                Localization.SetLocalizedText(dbEnterprise.LocalizedDescription, nativeLanguage,
                                                              enterprise.Description);
                        }
                        dbEnterprise.FacebookUrl = enterprise.FacebookUrl;
                        dbEnterprise.Name        = enterprise.Name;
                        dbEnterprise.TwitterUrl  = enterprise.TwitterUrl;
                        dbEnterprise.URL         = enterprise.WebsiteUrl;
                    }
                });
            }
        }
Beispiel #9
0
        public PermissionResult CheckDevicePermission(int userId, int deviceId)
        {
            var device = GetDevice(deviceId);

            if (device == null)
            {
                return(new PermissionResult(PermissionResults.InvalidObject,
                                            "The Device you are trying to access does not exist",
                                            new[] { new KeyValuePair <string, object>("deviceId", deviceId) }
                                            ));
            }

            var hasPermission = Rp.ExecuteAction(() => Context.GetDevicesForUser(userId).Select(ud => ud.PKID).Contains(deviceId));

            if (hasPermission)
            {
                return new PermissionResult {
                           Result = PermissionResults.Authorized
                }
            }
            ;

            return(RootRepository.SecurityRepository.IsSuperAdmin()
                                ? new PermissionResult {
                Result = PermissionResults.Authorized
            }
                                : new PermissionResult(PermissionResults.Unauthorized, "You are unauthorized to access this device.",
                                                       new[] { new KeyValuePair <string, object>("deviceId", deviceId), }));
        }
Beispiel #10
0
        private void DeleteEnterpriseLocationRecommendation(int deviceId, int enterpriseId, int enterpriseLocationId,
                                                            List <int> categoryIds)
        {
            if (categoryIds != null)
            {
                Rp.ExecuteAction(() =>
                {
                    var hotelBestOfEnterpriseLocationMaps =
                        (from hboelm in
                         ProxylessContext.HotelBestOfEnterpriseLocationMaps.Where(hboelm2 => hboelm2.HotelBestOfEnterpriseMap.IsActive)
                         let hboem = hboelm.HotelBestOfEnterpriseMap
                                     where hboem.FKDevice == deviceId &&
                                     hboem.EnterpriseCategoryMap.FKEnterprise == enterpriseId &&
                                     hboelm.FKEnterpriseLocation == enterpriseLocationId &&
                                     categoryIds.Contains(hboem.EnterpriseCategoryMap.CategoryMap.ChildCategory.PKID)
                                     select hboelm).ToList();

                    ProxylessContext.HotelBestOfEnterpriseLocationMaps.DeleteObjects(hotelBestOfEnterpriseLocationMaps);

                    var hotelBestOfEnterpriseMap =
                        (from hboem in ProxylessContext.HotelBestOfEnterpriseMaps.Where(hboem2 => hboem2.IsActive)
                         where hboem.FKDevice == deviceId &&
                         hboem.EnterpriseCategoryMap.FKEnterprise == enterpriseId &&
                         !hboem.HotelBestOfEnterpriseLocationMaps.Any()
                         select hboem).FirstOrDefault();

                    if (hotelBestOfEnterpriseMap != null)
                    {
                        ProxylessContext.HotelBestOfEnterpriseMaps.DeleteObject(hotelBestOfEnterpriseMap);
                    }
                });
            }
        }
Beispiel #11
0
        public SMSStockMessage SaveSMSStockMessage(int userId, SMSStockMessage message)
        {
            var result = RootRepository.HotelRepository.CheckHotelPermission(userId, message.FKHotel);

            if (result.Result == PermissionResults.Authorized)
            {
                if (message.PKID != 0)
                {
                    var msg = Rp.ExecuteAction(() => ProxylessContext.SMSStockMessages.FirstOrDefault(m => m.PKID == message.PKID));
                    if (msg != null)
                    {
                        msg.Name = message.Name;
                        msg.Text = message.Text;
                        ProxylessContext.LogValidationFailSaveChanges(string.Format("CU|{0}", userId));
                        return(msg);
                    }
                }
                else
                {
                    var msg = new SMSStockMessage
                    {
                        Name    = message.Name,
                        Text    = message.Text,
                        FKHotel = message.FKHotel
                    };
                    ProxylessContext.SMSStockMessages.Add(msg);
                    ProxylessContext.LogValidationFailSaveChanges(string.Format("CU|{0}", userId));
                    return(msg);
                }
            }
            return(null);
        }
Beispiel #12
0
        private void UpdateEnterpriseLocation(EnterpriseLocationModel enterpriseLocation)
        {
            if (enterpriseLocation != null)
            {
                Rp.ExecuteAction(() =>
                {
                    var dbEnterpriseLocation = (from el in ProxylessContext.EnterpriseLocations.Where(el2 => el2.IsActive)
                                                where el.PKID == enterpriseLocation.PKID
                                                select el).FirstOrDefault();

                    if (dbEnterpriseLocation != null)
                    {
                        dbEnterpriseLocation.Address1 = enterpriseLocation.Location != null ? enterpriseLocation.Location.Address1 : null;
                        dbEnterpriseLocation.Address2 = enterpriseLocation.Location != null ? enterpriseLocation.Location.Address2 : null;
                        dbEnterpriseLocation.City     = enterpriseLocation.Location != null ? enterpriseLocation.Location.City : null;
                        dbEnterpriseLocation.Country  = enterpriseLocation.Location != null && enterpriseLocation.Location.Country != null
                                                        ? enterpriseLocation.Location.Country.ISOCountryCode
                                                        : null;
                        dbEnterpriseLocation.Phone = enterpriseLocation.Phone;
                        dbEnterpriseLocation.PhoneISOCountryCode = enterpriseLocation.PhoneISOCountryCode;
                        dbEnterpriseLocation.State = enterpriseLocation.Location != null && enterpriseLocation.Location.State != null
                                                        ? enterpriseLocation.Location.State.ISOStateCode
                                                        : null;
                        dbEnterpriseLocation.PostalCode = enterpriseLocation.Location != null
                                                        ? enterpriseLocation.Location.PostalCode
                                                        : null;
                    }
                });
            }
        }
Beispiel #13
0
 public IQueryable <MarketingCampaign> GetMarketingCampaign(int id)
 {
     return(Rp.ExecuteAction(
                () =>
                ProxylessContext.MarketingCampaigns.Where(
                    x => x.PKID == id)
                ));
 }
Beispiel #14
0
        public List <ImageModel> GetCustomImages()
        {
            var currentUser = RootRepository.SecurityRepository.GetLoggedInUser();

            return(Rp.ExecuteAction(() => (from ci in Context.Images
                                           where ci.IsActive && ci.FKAccount == currentUser.FKAccount && ci.FKAccount != null
                                           select ci)).ToList().Select(i => new ImageModel(i)).ToList());
        }
Beispiel #15
0
 public IQueryable <SMSStockMessage> GetSmsStockMessage(int userId, int messageId)
 {
     return
         (Rp.ExecuteAction(
              () =>
              ProxylessContext.SMSStockMessages.Where(
                  m => m.PKID == messageId)));
 }
Beispiel #16
0
        public Device GetDevice(int deviceId)
        {
            RootRepository.SecurityRepository.AssertDevicePermissions(deviceId);

            var device = Rp.ExecuteAction(() => Context.Devices.FirstOrDefault(d => d.PKID == deviceId));

            return(device);
        }
Beispiel #17
0
        public List <Device> GetDevicesForUser(int contactUserId)
        {
            var devices = Rp.ExecuteAction(() => Context.GetDevicesForUser(contactUserId)
                                           .Include(x => x.Hotel)
                                           .Include(x => x.Hotel.HotelDetail).ToList());

            return(devices);
        }
Beispiel #18
0
        public int GetTodaysPostcardCount(int deviceId)
        {
            var count = Rp.ExecuteAction(() => Context.Postcards
                                         .Where(p => p.FKDevice == deviceId && p.SentDateTime >= DateTime.Today
                                                )).Count();

            return(count);
        }
Beispiel #19
0
 public IQueryable <SMSStockMessage> GetSMSStockMessages(int userId, int hotelId)
 {
     return
         (Rp.ExecuteAction(
              () =>
              ProxylessContext.SMSStockMessages.Where(
                  m => m.FKHotel == hotelId)));
 }
Beispiel #20
0
        public void InsertEnterpriseLocationTip(int deviceId, int userId, string tip, int enterpriseId, int enterpriseLocationId)
        {
            RootRepository.SecurityRepository.AssertDevicePermissions(deviceId);

            InsertTip(deviceId, userId, tip, null, enterpriseId, enterpriseLocationId);

            Rp.ExecuteAction(() => Context.LogValidationFailSaveChanges(RootRepository.SecurityRepository.AuditLogUserId));
        }
Beispiel #21
0
        public int GetTodaysRequestCount(int hotelId)
        {
            var count = Rp.ExecuteAction(() => Context.Requests
                                         .Where(r => r.RequestGroup.Hotel.PKID == hotelId &&
                                                r.RequestActions.OrderBy(ra => ra.ActionTime).FirstOrDefault().ActionTime > DateTime.Today
                                                )).Count();

            return(count);
        }
Beispiel #22
0
        public IEnumerable <ReleaseNote> GetReleaseNotificationsForUser(int contactUserId)
        {
            var releaseNotes = Rp.ExecuteAction(() => (from r in Context.ReleaseNotes
                                                       where r.ReleaseNoteContactUserReadMaps.All(m => m.FKContactUser != contactUserId) &&
                                                       r.NoteExpires > DateTime.Now
                                                       orderby r.ReleaseDate descending
                                                       select r)).ToList();

            return(releaseNotes);
        }
Beispiel #23
0
        public List <PostalCode> GetPostalCodes(string name)
        {
            var postalCodes = CacheManager.Get(
                "PostalCodes",
                () => Rp.ExecuteAction(() => (from pc in ProxylessContext.PostalCodes.Include(pc => pc.Country.States).Include(pc => pc.State)
                                              where pc.IsActive
                                              select pc)));

            return(postalCodes.Where(pc => pc.Name == name).ToList());
        }
Beispiel #24
0
        public void MapMobileBackgroundImage(int deviceId, Image image)
        {
            RootRepository.SecurityRepository.AssertDeviceAuthorization(deviceId);
            var hotelDetail =
                Rp.ExecuteAction(() => (from d in ProxylessContext.Devices where d.PKID == deviceId select d.Hotel.HotelDetail))
                .First();

            hotelDetail.MobileBackgroundImage = image;
            ProxylessContext.LogValidationFailSaveChanges(RootRepository.SecurityRepository.AuditLogUserId);
        }
Beispiel #25
0
        public IQueryable <SubDevice> GetReaderboards(int deviceId)
        {
            RootRepository.SecurityRepository.AssertDevicePermissions(deviceId);
            var readerBoards =
                Rp.ExecuteAction(
                    () =>
                    ProxylessContext.SubDevices.Where(x => x.DeviceType == DeviceType.InfoPointReaderboardTV && x.FKDevice == deviceId)
                    .Include(x => x.ReaderboardBackgroundImage));

            return(readerBoards);
        }
Beispiel #26
0
        public List <EventDetail> GetTodaysEvents(int?deviceId)
        {
            List <EventDetail> result;
            var startDateTime = deviceId.HasValue
                                ? GetLocalTimeForDevice(deviceId.Value, DateTime.Today)
                                : DateTime.Today.AddDays(1);
            var endDateTime = startDateTime.AddDays(1);

            if (deviceId.HasValue)
            {
                RootRepository.SecurityRepository.AssertDevicePermissions(deviceId);
                result =
                    Rp.ExecuteAction(
                        () =>
                        ProxylessContext.EventDetails.Include(e => e.EventLocation)
                        .Where(detail => detail.IsActive &&
                               detail.FKDevice == deviceId &&
                               (detail.LocalStartDateTime >= startDateTime && detail.LocalStartDateTime <= endDateTime)
                               )
                        .OrderBy(detail => detail.LocalStartDateTime)
                        .ThenBy(detail => detail.Name)
                        .Select(detail => detail).ToList());
            }
            else
            {
                var user = RootRepository.SecurityRepository.GetLoggedInUser();
                if (user.DefaultReachRole == null || (!user.DefaultReachRole.ManageAssignedEvents && user.DefaultReachRole.Name != "Super Admin"))
                {
                    throw new Exception("You are not an event manager, please select a device to view events.");
                }

                result =
                    Rp.ExecuteAction(
                        () => (from ed in ProxylessContext.EventDetails.Include(e => e.EventLocation)
                               where ed.IsActive &&
                               ed.EventGroup.EventGroupManagerMaps.Any(x => x.FKContactUser == user.PKID) &&
                               (ed.LocalStartDateTime >= startDateTime && ed.LocalStartDateTime <= endDateTime)
                               select ed)).ToList();
            }

            result.ForEach(detail =>
            {
                detail.IsAllDay = detail.LocalStartDateTime.TimeOfDay == new TimeSpan(0, 0, 0) &&
                                  detail.LocalEndDateTime.TimeOfDay == new TimeSpan(0, 0, 0) && detail.LocalStartDateTime < detail.LocalEndDateTime;
                if (!detail.IsAllDay)
                {
                    return;
                }
                detail.LocalStartDateTime = detail.LocalStartDateTime.Date;
                detail.LocalEndDateTime   = detail.LocalEndDateTime.Date.AddDays(-1);
            });

            return(result);
        }
Beispiel #27
0
        public int GetUserInteractionTodayCount(int deviceId)
        {
            var startDateTime = GetLocalTimeForDevice(deviceId, DateTime.Today);

            return(Rp.ExecuteAction(
                       () => (from t in Context.MobileClickTracks
                              where t.Hotel.Devices.Any(d => d.PKID == deviceId) &&
                              t.ClickDateTime > startDateTime
                              select t
                              ).Count()));
        }
Beispiel #28
0
        public MobileApp GetMobileApp(int id, string includes)
        {
            RootRepository.SecurityRepository.AssertSuperAdmin();
            var mobileApps = Rp.ExecuteAction(() =>
            {
                var h = ProxylessContext.MobileApps.Where(x => x.PKID == id);
                return(includes.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Aggregate(h, (current, include) => current.Include(include)));
            });

            return(mobileApps.FirstOrDefault());
        }
Beispiel #29
0
        public List <MobileApp> SearchMobileApp(string searchText, string includes)
        {
            RootRepository.SecurityRepository.AssertSuperAdmin();
            var mobileApps = Rp.ExecuteAction(() =>
            {
                var h = ProxylessContext.MobileApps.Where(x => x.Name.ToLower().Contains(searchText.ToLower()));
                return(includes.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Aggregate(h, (current, include) => current.Include(include)));
            });

            return(mobileApps.ToList());
        }
Beispiel #30
0
        private List <CategoryModel> GetCategories(int deviceId, bool onDevice)
        {
            List <CategoryModel> categories = null;

            var list = Rp.ExecuteAction(() => (from cm in Context.CategoryMaps
                                               let hcm = cm.HotelCategoryMaps.FirstOrDefault(hcm => hcm.FKDevice == deviceId)
                                                         where cm.IsActive &&
                                                         cm.ChildCategory.IsActive &&
                                                         cm.ParentCategory == null &&
                                                         (!onDevice || hcm != null)
                                                         select new
            {
                Category = new CategoryModel()
                {
                    BackgroundColor = cm.Color,
                    Name = cm.ChildCategory.Name,
                    OnDevice = hcm != null,
                    Order = hcm != null ? hcm.Ordinal : 0,
                    PKID = cm.ChildCategory.PKID,
                },
                Image = hcm.Image,
                DefaultImage = cm.Image,
            }).ToList());

            if (list != null)
            {
                list.ForEach(c =>
                {
                    if (c.Category != null)
                    {
                        if (c.DefaultImage != null)
                        {
                            c.Category.DefaultImage = new ImageModel(c.DefaultImage);
                        }

                        c.Category.Image = c.Category.DefaultImage;

                        if (c.Image != null)
                        {
                            c.Category.Image = new ImageModel(c.Image);
                        }

                        if (categories == null)
                        {
                            categories = new List <CategoryModel>();
                        }

                        categories.Add(c.Category);
                    }
                });
            }

            return(categories);
        }