//Delete location by id public static bool Delete(int Id) { GlobalSettings.LoggedInClientId = LocationService.GetById(Id).ClientId; int PartnerId = ClientService.GetById(Convert.ToInt32( GlobalSettings.LoggedInClientId)).PartnerId; GlobalSettings.LoggedInPartnerId = PartnerId; bool IsExists = IsChildEntityExist(Id); try { if (IsExists != true) { LocationDTO LocationDTO = new LocationDTO(); LocationDTO = GetById(Id); UnitOfWork uow = new UnitOfWork(); uow.LocationRepo.Delete(Id); uow.SaveChanges(); return true; } else return false; } catch { throw; } }
//Create location public static int Create(LocationDTO LocationDTO) { try { GlobalSettings.LoggedInClientId = LocationDTO.ClientId; int PartnerId = ClientService.GetById(LocationDTO.ClientId).PartnerId; GlobalSettings.LoggedInPartnerId = PartnerId; var Location = new Location(); UnitOfWork uow = new UnitOfWork(); Location = Transform.LocationToDomain(LocationDTO); uow.LocationRepo.Insert(Location); uow.SaveChanges(); Location.Id = Location.Id; return Location.Id; } catch (Exception) { throw; } }
//Edit location public static void Edit(LocationDTO LocationDTO) { try { GlobalSettings.LoggedInClientId = LocationDTO.ClientId; int PartnerId = ClientService.GetById(LocationDTO.ClientId).PartnerId; GlobalSettings.LoggedInPartnerId = PartnerId; UnitOfWork uow = new UnitOfWork(); Location Location = Transform.LocationToDomain(LocationDTO); uow.LocationRepo.Update(Location); uow.SaveChanges(); } catch { throw; } }
public void Edit(string accessId, LocationDTO LocationDTO) { try { LocationService.Edit(LocationDTO); } catch (TimeoutException) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.RequestTimeout) { Content = new StringContent("An error occurred, please try again or contact the administrator."), ReasonPhrase = "Critical Exception" }); } catch (Exception) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent("An error occurred, please try again or contact the administrator."), ReasonPhrase = "Critical Exception" }); } }
/// <summary> /// Get active or inactive Users by Client id /// </summary> /// <param name="ClientId">Id of the Client</param> /// <param name="search">search string</param> /// <param name="IsActive">TRUE OR FALSE</param> /// <param name="pagingInfo">pagingInfo object</param> /// <returns> Returns Active or Inactive user list </returns> public static List<UserDTO> GetUsersbyClientIdWithIsActive(int ClientId, string search, bool IsActive, PagingInfo pagingInfo) { List<UserDTO> UserDTOList = new List<UserDTO>(); try { UnitOfWork uow = new UnitOfWork(); int skip = (pagingInfo.Page - 1) * pagingInfo.ItemsPerPage; int take = pagingInfo.ItemsPerPage; IQueryable<User> User = uow.UserRepo.GetAll().Where(e => e.ClientId == ClientId && e.IsActive == IsActive).OrderBy(e => e.Name).AsQueryable();// .ToList().Skip(skip).Take(take); User = PagingService.Sorting<User>(User, pagingInfo.SortBy, pagingInfo.Reverse); User = User.Skip(skip).Take(take); if (User != null) { foreach (var user in User) { UserDTO UserDTO = new UserDTO(); UserDTO = Transform.UserToDTO(user); LocationDTO LocationDTO = new LocationDTO(); UserDTO.Location = LocationService.GetById(UserDTO.LocationId).Name; UserDTOList.Add(UserDTO); } if (search != "" && search != null) { //int LocationId = LocationService.GetByLocationName(search, ClientId); string LocationIdString = LocationService.GetLocationIdarrayByName(search, ClientId); bool IsDate = CommonService.IsDate(search); if (IsDate != true) { // string search List<UserDTO> UserDTOListSearch = new List<UserDTO>(); IQueryable<User> UserSearch = uow.UserRepo.GetAll().Where(e => (e.Email.ToLower().Contains(search.ToLower()) || e.Name.ToLower().Contains(search.ToLower()) || e.FirstName.ToLower().Contains(search.ToLower()) || e.LastName.ToLower().Contains(search.ToLower()) || (e.Mobile != null ? (e.Mobile.Contains(search)) : false) || (LocationIdString != null ? (e.LocationId.ToString().Split(',').Any(LocationId => LocationIdString.Contains(LocationId.ToString()))) : false)) && e.IsActive == IsActive && e.ClientId == ClientId).AsQueryable();//.OrderBy(e => e.Name).ToList().Skip(skip).Take(take); //(e.Location != null ? (e.Location.ToLower().Contains(search.ToLower())) : false) UserSearch = PagingService.Sorting<User>(UserSearch, pagingInfo.SortBy, pagingInfo.Reverse); UserSearch = UserSearch.Skip(skip).Take(take); foreach (var user in UserSearch) { UserDTO UserDTO = new UserDTO(); UserDTO = Transform.UserToDTO(user); LocationDTO LocationDTO = new LocationDTO(); UserDTO.Location = LocationService.GetById(UserDTO.LocationId).Name; UserDTOListSearch.Add(UserDTO); } return UserDTOListSearch; } else { } } ////else ////{ //// ////foreach (var item in User) //// ////{ //// //// //UserDTO UserDTO = new UserDTO(); //// //// UserDTOList.Add(Transform.UserToDTO(item)); //// ////} ////} } return UserDTOList; } catch (Exception) { throw; } }
public static Location LocationToDomain(LocationDTO LocationDTO) { if (LocationDTO == null) return null; Mapper.CreateMap<LocationDTO, Location>(); Location Location = Mapper.Map<Location>(LocationDTO); return Location; }
/// <summary> /// Register Client /// </summary> /// <param name="RegisterClientDTO">RegisterClientDTO object</param> /// <returns>Register Client details </returns> public static RegisterClientDTO RegisterClient(RegisterClientDTO RegisterClientDTO) { try { GlobalSettings.LoggedInClientId = null; GlobalSettings.LoggedInUserId = null; GlobalSettings.LoggedInPartnerId = null; RegisterClientDTO.UserType = "Admin"; RegisterClientDTO RegisterClientDTONew = new RegisterClientDTO(); ClientDTO ClientDTO = new ClientDTO(); ClientDTO.Company = RegisterClientDTO.Company; ClientDTO.Address = RegisterClientDTO.Address; ClientDTO.IsDatabaseUploaded = false; ClientDTO ClientDTONew = new ClientDTO(); ClientDTONew = ClientService.Create(ClientDTO); GlobalSettings.LoggedInClientId = ClientDTONew.Id; LocationDTO LocationDTO = new LocationDTO(); LocationDTO.Name = RegisterClientDTO.Location; LocationDTO.ClientId = ClientDTONew.Id; int LocationId = 0; LocationId = LocationService.Create(LocationDTO); UserDTO UserDTO = new UserDTO(); //UserDTO.Name = RegisterClientDTO.Name; UserDTO.FirstName = RegisterClientDTO.FirstName; UserDTO.LastName = RegisterClientDTO.LastName; UserDTO.Email = RegisterClientDTO.Email; UserDTO.Password = RegisterClientDTO.Password; UserDTO.Mobile = RegisterClientDTO.Mobile; UserDTO.LocationId = LocationId; UserDTO.ClientId = ClientDTONew.Id; UserDTO UserDTONew = new UserDTO(); UserDTONew = UserService.Create(UserDTO); UserDTONew.UserType = "Admin"; UserDTONew.UserAccessPrivileges = UserService.GetUserAccess(UserDTONew.UserType.ToString()); GlobalSettings.LoggedInUserId = UserDTONew.Id; //Assign client values to Registerclient RegisterClientDTONew.Address = ClientDTONew.Address; RegisterClientDTONew.ClientId = ClientDTONew.Id; RegisterClientDTONew.Company = ClientDTONew.Company; //Assign user values to Registerclient RegisterClientDTONew.Email = UserDTONew.Email; RegisterClientDTONew.Mobile = UserDTONew.Mobile; //RegisterClientDTONew.Name = UserDTONew.Name; RegisterClientDTONew.FirstName = UserDTONew.FirstName; RegisterClientDTONew.LastName = UserDTONew.LastName; RegisterClientDTONew.Password = UserDTONew.Password; RegisterClientDTONew.Id = UserDTONew.Id; RegisterClientDTONew.UserAccessPrivileges = UserDTONew.UserAccessPrivileges; return RegisterClientDTONew; } catch (msgBlasterValidationException) { throw; } catch (Exception) { //HttpContext.Current.Session["LoggedClient"] = null; //HttpContext.Current.Session["LoggedClientId"] = "0"; throw; } }