コード例 #1
0
        public IPagedList <UserModel> GetUserList(string sortOrder, string searchString, int pageNumber, int pageSize)
        {
            IPagedList <UserModel> res = null;

            try
            {
                using (UnitOfWork db = new UnitOfWork())
                {
                    //1.All records as result
                    var results = db.DB.GetUserList().ToList().ConvertAll(x => new UserModel
                    {
                        Id          = x.Id,
                        Firstname   = x.Firstname,
                        Lastname    = x.Lastname,
                        Phone       = x.Phone,
                        EmailId     = x.EmailId,
                        CountryName = x.CountryName,
                        CityName    = x.CityName,
                        Gender      = x.Gender,
                        PhotoUrl    = x.PhotoUrl,
                        Hobby       = db.DB.GetHobbyList(x.Id).FirstOrDefault()
                    }).ToList();

                    //2.result by searching (Filtering)
                    if (!String.IsNullOrEmpty(searchString))
                    {
                        results = results.Where(s => s.Firstname.ToLower().Contains(searchString.ToLower())).ToList();
                    }

                    //3.result by Sorting
                    switch (sortOrder)
                    {
                    case "Firstname_desc":
                        results = results.OrderByDescending(s => s.Firstname).ToList();
                        break;

                    case "Lastname":
                        results = results.OrderBy(s => s.Lastname).ToList();
                        break;

                    case "Lastname_desc":
                        results = results.OrderByDescending(s => s.Lastname).ToList();
                        break;

                    default:
                        results = results.OrderBy(s => s.Firstname).ToList();
                        break;
                    }
                    return(results.ToPagedList(pageNumber, pageSize));

                    //TO DO - Make sp for fatching only filtered result
                }
            }
            catch (Exception ex)
            {
                ErrorLogService.LogErrorOccured("Error", "GetUserList", "", ex.Message, 0, "UserService", ex.ToString());
            }
            return(res);
        }
コード例 #2
0
 public bool DeleteUser(int id)
 {
     try
     {
         using (UnitOfWork db = new UnitOfWork())
         {
             db.UserRepository.Delete(id);
             return(true);
         }
     }
     catch (Exception ex)
     {
         string InputData = string.Format(CultureInfo.InvariantCulture, "client_id: {0}", id);
         ErrorLogService.LogErrorOccured("Error", "DeleteUser", InputData, ex.Message, 0, "UserService", ex.ToString());
         return(false);
     }
 }
コード例 #3
0
        public bool AddEditUser(UserModel model)
        {
            User entity = new User();

            try
            {
                entity.Id        = model.Id;
                entity.Firstname = model.Firstname;
                entity.Lastname  = model.Lastname;
                entity.Phone     = model.Phone;
                entity.EmailId   = model.EmailId;
                entity.CountryId = model.CountryId;
                entity.CityId    = model.CityId;
                entity.Gender    = model.Gender;
                entity.Hobbies   = string.Join(",", model.HobbyList.Where(x => x.IsSelected == true).Select(x => x.Id));
                if (model.PhotoUrl != null)
                {
                    entity.PhotoUrl = model.PhotoUrl;
                }
                else
                {
                    entity.PhotoUrl = model.hdnPhotoUrl;
                }
                using (UnitOfWork db = new UnitOfWork())
                {
                    if (model.Id > 0)
                    {
                        db.UserRepository.Update(entity);
                    }
                    else
                    {
                        db.UserRepository.Insert(entity);
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                string InputData = string.Format(CultureInfo.InvariantCulture, "client_id: {0}", model.Id);
                ErrorLogService.LogErrorOccured("Error", "AddEditUser", InputData, ex.Message, 0, "UserService", ex.ToString());
                return(false);
            }
        }