public void FilteredShops_Test()
        {
            var shops = new ShopCollection();

            var shopOne = new Shop()
            {
                Address = "123",
                Id      = 1,
                Name    = "asdads",
                Website = "www.123.com",
                gpsX    = 2,
                gpsY    = 2
            };
            var shopTwo = new Shop()
            {
                Address = "456",
                Id      = 2,
                Name    = "qweqwe",
                Website = "www.456.com",
                gpsX    = 6,
                gpsY    = 6
            };

            shops.CreateShop(shopOne);
            shops.CreateShop(shopTwo);

            Assert.AreEqual(shopOne, shops.FilteredShops(1, 1, 4, 4).FirstOrDefault());
            Assert.AreEqual(1, shops.FilteredShops(1, 1, 4, 4).Count);
        }
Example #2
0
        public async Task <ShopCollection> CreateShopCollection(ShopCollection shopCollection)
        {
            shopCollection.AddedDate = DateTime.Now;
            await _context.ShopCollections.AddAsync(shopCollection);

            await _context.SaveChangesAsync();

            return(shopCollection);
        }
Example #3
0
        public async Task UpdateShopCollection(int id, ShopCollection shopCollection)
        {
            var updateShopCollection = await GetShopCollectionById(id);

            updateShopCollection.OrderBy         = shopCollection.OrderBy;
            updateShopCollection.Subtitle        = shopCollection.Subtitle;
            updateShopCollection.Title           = shopCollection.Title;
            updateShopCollection.BackgroundColor = shopCollection.BackgroundColor;
            updateShopCollection.BtnText         = shopCollection.BtnText;
            updateShopCollection.BtnUrl          = shopCollection.BtnUrl;
            updateShopCollection.SoftDeleted     = shopCollection.SoftDeleted;
            updateShopCollection.ProductId       = shopCollection.ProductId;
            updateShopCollection.ModifiedDate    = DateTime.Now;
            await _context.SaveChangesAsync();
        }
Example #4
0
        public static void Execute()
        {
            var shops = new ShopCollection();

            var depthFirstSearch = new DepthFirstSearch();
            var path1            = depthFirstSearch.Search(shops[5], shops[12]);

            PrintPath(path1);
            var path2 = depthFirstSearch.Search(shops[5], shops[14]);

            PrintPath(path2);

            var breadthFirstSearch = new BreadthFirstSearch();
            var path3 = breadthFirstSearch.Search(shops[5], shops[12]);

            PrintPath(path3);
            var path4 = breadthFirstSearch.Search(shops[5], shops[14]);

            PrintPath(path4);
        }
        public void CreateShopGetShop_Test()
        {
            //Arrange
            ShopCollection shops        = new ShopCollection();
            Shop           shopExpected = new Shop()
            {
                Address = "123",
                Id      = 1,
                Name    = "asdads",
                Website = "www.123.com",
                gpsX    = 5,
                gpsY    = 5
            };

            //Act
            shops.CreateShop(shopExpected);
            Shop shopActual = shops.ReaedShop(1);

            //Assert
            Assert.AreEqual(shopExpected, shopActual);
        }
        /// <summary>
        /// Caches the shop
        /// </summary>
        /// <param name="npc">Npc who requires his shop to be cached</param>
        protected virtual void OnCacheShop(BaseNPC npc)
        {
            string filename = Server.SecurePath("~/shops/{0}.xml", npc.ModelId);

            _shoplist = ShopCollection.FromFile(filename);
        }
Example #7
0
        public Enums.LoginStatus getLogin(string username, string password)
        {
            try
            {
                myShop = new MyshopDb();
                string passHash = Utility.getHash(password);

                var isAuthenticated = myShop.Gbl_Master_User.Where(user => user.Username.Equals(username)).FirstOrDefault();

                if (isAuthenticated == null)
                {
                    return(Enums.LoginStatus.NotExist);
                }
                else if (isAuthenticated.IsActive == false)
                {
                    return(Enums.LoginStatus.Inactive);
                }
                else if (isAuthenticated.IsBlocked == true)
                {
                    return(Enums.LoginStatus.UserBlocked);
                }
                else if (isAuthenticated.IsDeleted == true)
                {
                    return(Enums.LoginStatus.UserDeleted);
                }
                else
                {
                    var login = myShop.Logins.Where(log => log.UserId.Equals(isAuthenticated.UserId) && log.IsDeleted == false).FirstOrDefault();
                    if (login != null)
                    {
                        if (login.IsLoginBlocked)
                        {
                            return(Enums.LoginStatus.LoginBlocked);
                        }
                        else if (isAuthenticated.Password != passHash)
                        {
                            login.LoginAttempt       += 1;
                            login.ModificationDate    = DateTime.Now;
                            login.ModifiedBy          = isAuthenticated.UserId;
                            myShop.Entry(login).State = EntityState.Modified;
                            myShop.SaveChanges();
                            return(Enums.LoginStatus.InvalidCredential);
                        }
                        else if (login.LoginAttempt >= 3)
                        {
                            login.IsLoginBlocked      = true;
                            login.ModificationDate    = DateTime.Now;
                            login.ModifiedBy          = isAuthenticated.UserId;
                            myShop.Entry(login).State = EntityState.Modified;
                            myShop.SaveChanges();
                            return(Enums.LoginStatus.AttemptExceeded);
                        }
                    }
                    else
                    {
                        Login newLogin = new Login();
                        newLogin.CreationBy          = WebSession.UserId;
                        newLogin.UserId              = isAuthenticated.UserId;
                        newLogin.ModifiedBy          = WebSession.UserId;
                        newLogin.ModificationDate    = DateTime.Now;
                        newLogin.LoginDate           = DateTime.Now;
                        newLogin.IsSync              = false;
                        newLogin.IsReset             = false;
                        newLogin.IsLoginBlocked      = false;
                        newLogin.IsDeleted           = false;
                        newLogin.CreationDate        = DateTime.Now;
                        myShop.Entry(newLogin).State = EntityState.Added;
                        myShop.SaveChanges();
                    }
                    var userType = myShop.Gbl_Master_UserType.Where(type => type.UserTypeId.Equals(isAuthenticated.UserTypeId) && type.IsDeleted == false).FirstOrDefault();
                    List <CustomPermission> userPermission = (from permission in myShop.Gbl_Master_User_Permission.Where(x => x.UserId.Equals(isAuthenticated.UserId) && x.IsDeleted == false)
                                                              from page in myShop.Gbl_Master_Page.Where(x => x.PageId.Equals(permission.PageId) && x.IsDeleted == false)
                                                              from module in myShop.Gbl_Master_AppModule.Where(x => x.ModuleId.Equals(page.ModuleId) && x.IsDeleted == false)
                                                              select new CustomPermission
                    {
                        Delete = permission.Delete,
                        IsBlockAccess = permission.IsBlockAccess,
                        Read = permission.Read,
                        Update = permission.Update,
                        Write = permission.Write,
                        UserId = permission.UserId,
                        PageId = permission.PageId,
                        PageName = page.PageName,
                        Url = page.Url,
                        ParentId = page.ParentId,
                        ModuleId = page.ModuleId,
                        ModuleName = module.ModuleName
                    }).ToList();
                    var shopname =
                        (from shopMap in myShop.User_ShopMapper
                         join shop in myShop.Gbl_Master_Shop on shopMap.ShopId equals shop.ShopId
                         where shopMap.IsDeleted == false && shop.IsDeleted == false && shopMap.UserId == isAuthenticated.UserId
                         select new
                    {
                        shop.ShopId,
                        ShopName = shop.Name,
                        shop.Mobile,
                        shop.Address,
                        shop.Email,
                        State = shop.Gbl_Master_State.StateName,
                        Distict = shop.Gbl_Master_City.CityName,
                        shop.Owner
                    }).ToList();

                    List <ShopCollection> shopCol = new List <ShopCollection>();
                    if (shopname.Count > 0)
                    {
                        WebSession.ShopId   = shopname[0].ShopId;
                        WebSession.ShopName = shopname[0].ShopName;
                        foreach (var item in shopname)
                        {
                            ShopCollection newShop = new ShopCollection();
                            newShop.ShopId      = item.ShopId;
                            newShop.ShopName    = item.ShopName;
                            newShop.ShopCity    = item.Distict;
                            newShop.OwnerEmail  = item.Email;
                            newShop.OwnerMobile = item.Mobile;
                            newShop.ShopAddress = item.Address;
                            newShop.ShopState   = item.State;
                            shopCol.Add(newShop);
                        }
                    }

                    var downtime = myShop.Gbl_AppDowntime.Where(x => x.IsDeleted == false && x.DownTimeEnd >= DateTime.Now).FirstOrDefault();
                    if (downtime != null)
                    {
                        WebSession.DowntimeEnd     = downtime.DownTimeEnd;
                        WebSession.DowntimeStart   = downtime.DownTimeStart;
                        WebSession.DowntimeMessage = downtime.Message;
                    }
                    else
                    {
                        WebSession.DowntimeMessage = string.Empty;
                    }
                    if (login != null)
                    {
                        login.LoginAttempt        = 0;
                        login.LoginDate           = DateTime.Now;
                        login.ModificationDate    = DateTime.Now;
                        login.IsSync              = false;
                        login.ModifiedBy          = isAuthenticated.UserId;
                        myShop.Entry(login).State = EntityState.Modified;
                    }

                    WebSession.UserId        = isAuthenticated.UserId;
                    WebSession.Firstname     = isAuthenticated.Firstname;
                    WebSession.Lastname      = isAuthenticated.Lastname;
                    WebSession.UserIsActive  = isAuthenticated.IsActive;
                    WebSession.UserIsDeleted = isAuthenticated.IsDeleted;
                    WebSession.UserIsBlocked = isAuthenticated.IsBlocked;
                    WebSession.UserMobile    = isAuthenticated.Mobile;
                    WebSession.Username      = isAuthenticated.Username;
                    WebSession.ShopList      = shopCol;
                    WebSession.UserPhoto     = isAuthenticated.Photo == null ? string.Empty : Convert.ToBase64String(isAuthenticated.Photo);
                    WebSession.UserType      = isAuthenticated.Gbl_Master_UserType.UserType;
                    WebSession.UserGender    = isAuthenticated.Gender.ToUpper();

                    if (userType != null)
                    {
                        WebSession.UserType = userType.UserType;
                    }
                    if (userPermission != null)
                    {
                        WebSession.Permission = userPermission;
                    }

                    var notification = myShop.Gbl_Master_Notification.Where(x =>
                                                                            x.IsDeleted == false &&
                                                                            x.IsPushed == true &&
                                                                            x.IsRead == false &&
                                                                            x.MessageExpireDate >= DateTime.Now &&
                                                                            x.ShopId.Equals(WebSession.ShopId) &&
                                                                            (x.UserId.Equals(WebSession.UserId) || x.IsForAll == true) &&
                                                                            (x.Gbl_Master_NotificationType.NotificationType.ToLower().IndexOf("push") > -1 || x.Gbl_Master_NotificationType.NotificationType.ToLower().IndexOf("web") > -1)
                                                                            ).ToList();

                    List <WebSessionNotificationList> _notificationList = new List <WebSessionNotificationList>();

                    foreach (Gbl_Master_Notification item in notification)
                    {
                        WebSessionNotificationList _newItem = new WebSessionNotificationList();
                        _newItem.Message        = item.Message;
                        _newItem.Sender         = string.Format("{0} {1}", item.Gbl_Master_User.Firstname, item.Gbl_Master_User.Lastname);
                        _newItem.Photo          = Convert.ToBase64String(item.Gbl_Master_User.Photo);
                        _newItem.ReceiveDate    = Convert.ToDateTime(item.PushedDate);
                        _newItem.NotificationId = item.NotificationId;
                        TimeSpan span = DateTime.Now.Subtract(Convert.ToDateTime(item.PushedDate));
                        if (span.Days == 1)
                        {
                            _newItem.ReceiveTime = string.Format("{0} day ago", span.Days.ToString());
                        }
                        else if (span.Days > 1)
                        {
                            _newItem.ReceiveTime = string.Format("{0} days ago", span.Days.ToString());
                        }
                        else if (span.Hours >= 1 && span.Hours <= 23)
                        {
                            _newItem.ReceiveTime = string.Format("{0} hour ago", span.Hours.ToString());
                        }
                        else //if (span.Minutes < 60)
                        {
                            _newItem.ReceiveTime = string.Format("{0} min ago", span.Minutes.ToString());
                        }

                        _notificationList.Add(_newItem);
                    }
                    WebSession.NotificationList  = _notificationList;
                    WebSession.NotificationCount = _notificationList.Count();



                    var taskUser = myShop.Gbl_Master_Task.Where(x =>
                                                                x.IsDeleted == false &&
                                                                !x.IsCompleted &&
                                                                x.ShopId.Equals(WebSession.ShopId) &&
                                                                x.AssignedUserId.Equals(WebSession.UserId)).ToList();

                    List <TaskUserModel> _taskList = new List <TaskUserModel>();
                    foreach (Gbl_Master_Task item in taskUser)
                    {
                        TaskUserModel _newItem = new TaskUserModel();
                        _newItem.TaskId               = item.TaskId;
                        _newItem.CreatedDate          = item.CreatedDate;
                        _newItem.TaskCreatedByName    = item.Gbl_Master_User.Firstname + " " + item.Gbl_Master_User.Lastname;
                        _newItem.TaskCreatedById      = item.Gbl_Master_User.UserId;
                        _newItem.TaskCreatedByPhoto   = Convert.ToBase64String(Utility.GetImageThumbnails(item.Gbl_Master_User.Photo, 30));
                        _newItem.IsImporatant         = item.IsImportant;
                        _newItem.TaskAssignedUserId   = item.AssignedUserId;
                        _newItem.TaskAssignedUserName = item.Gbl_Master_User1.Firstname + " " + item.Gbl_Master_User1.Lastname;;
                        _newItem.Priority             = item.Priority;
                        _newItem.TaskDetails          = item.TaskDetails;
                        TimeSpan span = DateTime.Now.Subtract(Convert.ToDateTime(item.CreatedDate));
                        if (span.Days == 1)
                        {
                            _newItem.TaskAssignedTime = string.Format("{0} day ago", span.Days.ToString());
                        }
                        else if (span.Days > 1)
                        {
                            _newItem.TaskAssignedTime = string.Format("{0} days ago", span.Days.ToString());
                        }
                        else if (span.Hours >= 1 && span.Hours <= 23)
                        {
                            _newItem.TaskAssignedTime = string.Format("{0} hour ago", span.Hours.ToString());
                        }
                        else //if (span.Minutes < 60)
                        {
                            _newItem.TaskAssignedTime = string.Format("{0} min ago", span.Minutes.ToString());
                        }

                        _taskList.Add(_newItem);
                    }
                    WebSession.TaskCount = taskUser.Count();
                    WebSession.TaskList  = _taskList;

                    if (isAuthenticated.HasDefaultPassword ?? false)
                    {
                        WebSession.HasDefaultPassword = true;
                        return(Enums.LoginStatus.HasDefaultPassword);
                    }
                    else
                    {
                        return(shopname.Count > 0 ? Enums.LoginStatus.Authenticate : Enums.LoginStatus.NoShopMapped);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (myShop != null)
                {
                    myShop = null;
                }
            }
        }
        /// <summary>
        /// Caches the shop items.
        /// </summary>
        /// <remarks>
        /// This will load all shop items from the data directory from read from
        /// file shops/cathelya.xml.
        /// </remarks>
        /// <param name="npc">Npc who requires caching</param>
        protected virtual void OnCacheShop(BaseNPC npc)
        {
            string filename = Server.SecurePath("~/shops/Catheleya.xml");

            _shoplist = ShopCollection.FromFile(filename);
        }
        public void AllShops_Tests()
        {
            var shops = new ShopCollection();

            var shopOne = new Shop()
            {
                Address = "123",
                Id      = 1,
                Name    = "asdads",
                Website = "www.123.com",
                gpsX    = 2,
                gpsY    = 2
            };
            var shopTwo = new Shop()
            {
                Address = "456",
                Id      = 2,
                Name    = "qweqwe",
                Website = "www.456.com",
                gpsX    = 5,
                gpsY    = 5
            };
            var shopThree = new Shop()
            {
                Address = "789",
                Id      = 3,
                Name    = "zxczxc",
                Website = "www.789.com",
                gpsX    = 8,
                gpsY    = 8
            };
            var shopFour = new Shop()
            {
                Address = "889",
                Id      = 4,
                Name    = "zxc3zxc",
                Website = "www.7829.com",
                gpsX    = 10,
                gpsY    = 10
            };
            var shopFive = new Shop()
            {
                Address = "7989",
                Id      = 5,
                Name    = "z23xczxc",
                Website = "www.78923.com",
                gpsX    = 12,
                gpsY    = 12
            };

            var paramX = 1;
            var paramY = 1;

            shops.CreateShop(shopTwo);
            shops.CreateShop(shopOne);
            shops.CreateShop(shopThree);
            shops.CreateShop(shopFive);
            shops.CreateShop(shopFour);

            Assert.AreEqual(shopOne, shops.AllShops(paramX, paramY).FirstOrDefault());
            Assert.AreEqual(shopThree, shops.AllShops(paramX, paramY)[2]);
            Assert.AreEqual(shopFive, shops.AllShops(paramX, paramY)[4]);
        }
Example #10
0
 private void Start()
 {
     instance = this;
 }