Exemple #1
0
        public ActionResult CreateTaskUser(TaskUserModel vm)
        {
            var list = _context.tblUserRoleAssigns.Where(x => x.TaskId == vm.TaskId);

            if (list != null)
            {
                _context.tblUserRoleAssigns.RemoveRange(list);
                _context.SaveChanges();
            }

            if (vm.UserSelected != null)
            {
                foreach (var user in vm.UserSelected)
                {
                    int userId     = Convert.ToInt16(user);
                    var roleassign = new tblUserRoleAssign();
                    //roleassign.ClientId = 0;
                    //roleassign.ProjectId = 0;
                    roleassign.TaskId       = vm.TaskId;
                    roleassign.AssignUserId = userId;
                    _context.tblUserRoleAssigns.Add(roleassign);
                    _context.SaveChanges();
                }
            }
            return(RedirectToAction("Index", new { area = "Task" }));
        }
Exemple #2
0
        public ActionResult ViewTaskUser(int id)
        {
            TaskUserModel vm = new TaskUserModel();

            vm.TaskId   = id;
            vm.AllUsers = new SelectList((from user in _context.tblUsers
                                          join role in _context.tblRoles on user.RoleId equals role.RoleId
                                          select new { UserId = user.UserId.ToString(), UserName = user.FullName, role.RoleDesc }).ToList(), "UserId", "UserName", "RoleDesc ", 0);

            vm.UserSelected = _context.tblUserRoleAssigns.Where(x => x.TaskId == id).ToList().Select(e => e.AssignUserId.ToString().Trim()).ToArray();
            return(PartialView("_AddTaskUser", vm));
        }
Exemple #3
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;
                }
            }
        }