Beispiel #1
0
 public bool DeletePhoto(Guid id)
 {
     using (FusionFaceDb db = new FusionFaceDb())
     {
         Photo photo = db.Photos.Where(p => p.ID == id).FirstOrDefault();
         photo.IsDeleted = true;
         db.SaveChanges();
         return(true);
     }
 }
Beispiel #2
0
        /// <summary>
        /// To Validate Login and return UserProfile for Authorization
        /// </summary>
        /// <param name="loginInfo"></param>
        /// <returns></returns>
        public UserProfile Authenticate(LoginInfo loginInfo)
        {
            UserProfile result = null;

            if (!string.IsNullOrEmpty(loginInfo.Password) &&
                !string.IsNullOrEmpty(loginInfo.Username))
            {
                string hashedPassword = Hash(loginInfo.Password);

                using (FusionFaceDb db = new FusionFaceDb())
                {
                    DateTime now = DateTime.Now;

                    var q = from u in db.UserMasters
                            where u.Username == loginInfo.Username &&
                            u.Password == hashedPassword &&
                            !u.IsDeleted &&
                            (u.AccountBlockedExpiry == null || u.AccountBlockedExpiry > now)
                            select u;

                    if (q.Count() > 0)
                    {
                        UserMaster uMaster = q.First();



                        result = new UserProfile()
                        {
                            ID        = uMaster.ID,
                            Username  = uMaster.Username,
                            LastLogin = uMaster.LastLoginTime
                        };

                        //Record LastLoginTime
                        uMaster.LastLoginTime    = DateTime.Now;
                        uMaster.PasswordTryCount = 0;

                        db.SaveChanges();

                        #region Permissions
                        var z = from ur in db.UserGroups
                                join p in db.Permissions on ur.GroupID equals p.GroupID
                                where ur.UserID == uMaster.ID
                                select p;

                        if (z.Count() > 0)
                        {
                            List <Permission> permissions = z.Distinct().ToList();

                            foreach (Permission p in permissions)
                            {
                                if (!result.Permissions.Contains(p.FunctionID))
                                {
                                    result.Permissions.Add(p.FunctionID);
                                }
                            }
                        }
                        #endregion

                        #region Menus
                        result.Menus.AddRange(GetMenuItemList(result.Permissions));
                        #endregion

                        #region Roles
                        var gr = from ur in db.UserGroups
                                 join g in db.GroupMasters on ur.GroupID equals g.ID
                                 where ur.UserID == uMaster.ID
                                 select g;

                        if (gr.Count() > 0)
                        {
                            List <GroupMaster> groups = gr.Distinct().ToList();

                            foreach (GroupMaster grp in groups)
                            {
                                if (!result.Roles.Contains(grp.Name))
                                {
                                    result.Roles.Add(grp.Name);
                                }
                            }
                        }
                        #endregion
                    }
                    else
                    {
                    }
                }
            }

            return(result);
        }