예제 #1
0
        /// <summary>
        /// To Delete the User
        /// </summary>
        /// <CreatedBy>Manoj Jaswal</CreatedBy>
        /// <CreatedDate>2015-03-05</CreatedDate>
        /// <param name="UserId"></param>
        /// <param name="DeletedBy"></param>
        public Result DeleteUser(long UserId, long DeletedBy, DARModel objDAR)
        {
            long   UserType = 0;
            Result result;
            long   count = 0;

            try
            {
                ObjUserRepository      = new UserRepository();
                objCommonMethodManager = new CommonMethodManager();
                UserRegistration obj_UserRegistration = ObjUserRepository.GetAll(x => x.UserId == UserId).FirstOrDefault();
                if (obj_UserRegistration != null)
                {
                    UserType = obj_UserRegistration.UserType;

                    using (workorderEMSEntities context = new workorderEMSEntities())
                    {
                        if (UserType == 6)
                        {
                            count = (from o in context.AdminLocationMappings
                                     join ur in context.UserRegistrations
                                     on o.AdminUserId equals ur.UserId

                                     where
                                     ur.IsLoginActive == true &&
                                     ur.IsEmailVerify == true &&
                                     ur.IsDeleted == false &&
                                     ur.UserId == UserId &&
                                     o.IsDeleted == false
                                     select o.AdminUserId
                                     ).Count();
                        }
                        else if (UserType == 2)
                        {
                            count = (from o in context.ManagerLocationMappings
                                     join ur in context.UserRegistrations
                                     on o.ManagerUserId equals ur.UserId

                                     where
                                     ur.IsLoginActive == true &&
                                     ur.IsEmailVerify == true &&
                                     ur.IsDeleted == false &&
                                     o.IsDeleted == false &&
                                     ur.UserId == UserId

                                     select o.ManagerUserId
                                     ).Count();
                        }
                    }

                    if (count == 0)
                    {
                        obj_UserRegistration.IsDeleted     = true;
                        obj_UserRegistration.IsLoginActive = false;
                        obj_UserRegistration.DeletedDate   = DateTime.UtcNow;
                        obj_UserRegistration.DeletedBy     = DeletedBy;
                        ObjUserRepository.SaveChanges();

                        objDAR.TaskType        = (long)TaskTypeCategory.UserDelete;
                        objDAR.ActivityDetails = DarMessage.UserDeleteDar(obj_UserRegistration.FirstName + ' ' + obj_UserRegistration.LastName);

                        #region Save DAR
                        result = objCommonMethodManager.SaveDAR(objDAR);
                        #endregion Save DAR
                        return(Result.Delete);
                    }
                    else
                    {
                        return(Result.ExistRecord);
                    }
                }
                else
                {
                    return(Result.DoesNotExist);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #2
0
        /// <summary>
        /// To Delete the User permanently
        /// </summary>
        /// <CreatedBy>Vijay Sahu</CreatedBy>
        /// <CreatedDate>2015-06-22</CreatedDate>
        public Tuple <int, string> DeleteUserFromUserList(long UserId, long DeletedBy, DARModel objDAR)
        {
            StringBuilder sb    = new StringBuilder();
            int           count = 0;

            try
            {
                ObjUserRepository = new UserRepository();
                CommonMethodManager objCommonMethodManager = new CommonMethodManager();
                UserRegistration    obj_UserRegistration   = ObjUserRepository.GetAll(x => x.UserId == UserId).FirstOrDefault();
                if (obj_UserRegistration != null)
                {
                    //UserType = obj_UserRegistration.UserType;
                    workorderEMSEntities Context = new workorderEMSEntities();

                    List <ssp_DeleteUser_Result> resu = Context.ssp_DeleteUser(UserId, DeletedBy).ToList();



                    count = Convert.ToInt32(resu.Select(x => x.Result).FirstOrDefault());
                    if (count == 0) //--SELECT 0,0,0,'There is one or more than one location where he is only one manager'
                    {
                        sb.Append("You can't delete this user because is the only manager for location(s) ");
                        foreach (var locName in resu)
                        {
                            sb.Append("<strong>" + locName.LocationName + "<strong>, ");
                        }

                        try
                        {
                            if (sb.Length > 2 && sb.ToString().Contains(","))
                            {
                                sb.Remove(sb.Length - 2, 2).Append(".");
                            }
                        }
                        catch
                        {
                        }
                    }
                    else if (count == 1)    //--SELECT 1,0,0,'There is no location where he is only one manager'
                    {
                        obj_UserRegistration.IsDeleted     = true;
                        obj_UserRegistration.IsLoginActive = false;
                        obj_UserRegistration.DeletedDate   = DateTime.UtcNow;
                        obj_UserRegistration.DeletedBy     = DeletedBy;
                        ObjUserRepository.SaveChanges();

                        objDAR.TaskType        = (long)TaskTypeCategory.UserDelete;
                        objDAR.ActivityDetails = DarMessage.UserDeleteDar(obj_UserRegistration.FirstName + ' ' + obj_UserRegistration.LastName);

                        #region Save DAR
                        objCommonMethodManager.SaveDAR(objDAR);
                        #endregion Save DAR

                        sb.Clear();
                        sb.Append(resu.Select(x => x.LocationName).FirstOrDefault() + ".");
                    }
                    else if (count == 2) //--SELECT 2,0,0,'You are not authorised to delete this user'
                    {
                        sb.Clear();
                        sb.Append(resu.Select(x => x.LocationName).FirstOrDefault() + ".");
                    }
                }
                else
                {
                    sb.Clear();
                    sb.Append("Please provide proper details for execute delete operation.");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            Tuple <int, string> returnResult = new Tuple <int, string>(count, sb.ToString());
            return(returnResult);
        }