protected async Task <ServiceResult <bool> > GetAutorizedOrganizationStatusById(long organizationId) { ServiceResult <bool> result; ServiceResult <List <OrganizationBo> > resultList = await GetAutorizedOrganizationList(); if (!resultList.Success || resultList.Data == null) { result = new ServiceResult <bool>(false, true, resultList.Error); } else { List <OrganizationBo> organizationlist = resultList.Data; OrganizationBo dto = organizationlist.FirstOrDefault(x => x.Id == organizationId); if (dto != null) { result = new ServiceResult <bool>(true, true, ""); } else { result = new ServiceResult <bool>(false, true, ""); } } return(result); }
public async Task <GenericResponse <OrganizationDto> > Post([FromBody] OrganizationDto dto) { if (dto.ParentId.HasValue && dto.ParentId > 0) { // Yetki kontrolü yapılıyor ServiceResult <bool> resultAutorized = await GetAutorizedOrganizationStatusById(dto.ParentId.Value); if (!resultAutorized.Success || !resultAutorized.Data) { return(GenericResponse <OrganizationDto> .Error(ResultType.Error, "Not Autorized Access!", "O_PST_01", StatusCodes.Status203NonAuthoritative)); } } else { return(GenericResponse <OrganizationDto> .Error(ResultType.Error, "Parent organization identifer not found!", "O_PST_02", StatusCodes.Status404NotFound)); } OrganizationBo bo = OrganizationBo.ConvertToBusinessObject(dto); ServiceResult <OrganizationBo> result = await serviceManager.Organization_Service.CreateAsync(bo); if (result.Success) { bo = result.Data; await serviceManager.CommitAsync(); return(GenericResponse <OrganizationDto> .Ok(OrganizationBo.ConvertToDto(bo))); } else { return(GenericResponse <OrganizationDto> .Error(ResultType.Error, "Parent organization identifer not found!", "O_PST_03", StatusCodes.Status500InternalServerError)); } }
public async Task <GenericResponse <OrganizationDto> > Get(long id) { // Yetki kontrolü yapılıyor ServiceResult <bool> resultAutorized = await GetAutorizedOrganizationStatusById(id); if (!resultAutorized.Success || !resultAutorized.Data) { return(GenericResponse <OrganizationDto> .Error(ResultType.Error, "Not Autorized Access!", "O_G_01", StatusCodes.Status203NonAuthoritative)); } OrganizationBo bo = null; ServiceResult <OrganizationBo> result = await serviceManager.Organization_Service.GetByIdAsync(id); if (result.Success) { bo = result.Data; } else { Log(result.Error, LogLevel.Error, this.ControllerContext.RouteData.Values); } if (bo == null) { return(GenericResponse <OrganizationDto> .Error(ResultType.Error, "User Not Found!", "O_G_02", StatusCodes.Status404NotFound)); } return(GenericResponse <OrganizationDto> .Ok(OrganizationBo.ConvertToDto(bo))); }
public async Task <GenericResponse> Put(long id, OrganizationDto dto) { if (id != dto.Id) { return(GenericResponse.Error(ResultType.Error, "Ids are mismatch!", "O_PT_01", StatusCodes.Status500InternalServerError)); } try { // Yetki kontrolü yapılıyor ServiceResult <bool> resultAutorized = await GetAutorizedOrganizationStatusById(dto.Id); if (!resultAutorized.Success || !resultAutorized.Data) { return(GenericResponse.Error(ResultType.Error, "Not Autorized Access!", "O_PT_02", StatusCodes.Status203NonAuthoritative)); } OrganizationBo bo = OrganizationBo.ConvertToBusinessObject(dto); ServiceResult serviceResult = await serviceManager.Organization_Service.UpdateAsync(id, bo); if (serviceResult.Success) { await serviceManager.CommitAsync(); return(GenericResponse.Ok()); } else { return(GenericResponse.Error(ResultType.Error, serviceResult.Error, "O_PT_03", StatusCodes.Status500InternalServerError)); } } catch (Exception ex) { Log(ex.Message, LogLevel.Error, this.ControllerContext.RouteData.Values); return(GenericResponse.Error(ResultType.Error, ex.Message, "O_PT_04", StatusCodes.Status500InternalServerError)); } }
public async Task <ServiceResult <IEnumerable <UserLoginBo> > > GetListAsync(long organizationId, FilterCriteria filterCriteria = null) { IEnumerable <UserLoginBo> listBo = null; ServiceResult <IEnumerable <UserLoginBo> > resultList = null; OrganizationBo dto = null; List <OrganizationBo> orgDtos; CultureInfo enCulture = new CultureInfo("en-US"); ServiceResult <OrganizationBo> result = await serviceManager.Organization_Service.GetByIdAsync(organizationId); if (!result.Success || result.Data == null) { return(new ServiceResult <IEnumerable <UserLoginBo> >(null, false, "Organization Not Found!")); } dto = result.Data; ServiceResult <List <OrganizationBo> > orgResults = await serviceManager.Organization_Service.GetOrganizationHierarchicaly(dto); if (!orgResults.Success || orgResults.Data == null || orgResults.Data.Count == 0) { return(new ServiceResult <IEnumerable <UserLoginBo> >(null, false, "Organizations Not Found!")); } orgDtos = orgResults.Data; List <long> orgIds = orgDtos.Select(x => x.Id).ToList(); if (filterCriteria == null) { filterCriteria = new FilterCriteria(); } var query = PredicateBuilder.True <UserLogin>(); foreach (DictonaryFilter item in filterCriteria.DictonaryBasedFilter) { switch (item.Key.ToLower(enCulture)) { case "user_id": { long userId = 0; if (!long.TryParse(item.Data, out userId)) { return(new ServiceResult <IEnumerable <UserLoginBo> >(null, false, "UserId Not Available!")); } switch (item.OperandType) { case OperandType.Equal: query = query.And(x => x.UserId == userId); break; case OperandType.NotEqual: query = query.And(x => x.UserId != userId); break; case OperandType.Like: query = query.And(x => EF.Functions.Like(x.UserId.ToString(), "%" + item.Data.ToLower() + "%")); break; } } break; } } query = query.And(x => orgIds.Contains(x.User.OrganizationId)); filterCriteria.IncludeProperties = "User"; resultList = await FindAsync(filterCriteria, query); if (resultList.Success) { listBo = resultList.Data; } else { return(new ServiceResult <IEnumerable <UserLoginBo> >(null, false, resultList.Error)); } if (listBo == null) { return(new ServiceResult <IEnumerable <UserLoginBo> >(null, false, "Not Found!")); } return(new ServiceResult <IEnumerable <UserLoginBo> >(listBo, true, "")); }
public async Task <GenericResponse <IEnumerable <OrganizationDto> > > GetList([FromBody] FilterCriteria filterCriteria) { IEnumerable <OrganizationBo> listBo = null; ServiceResult <IEnumerable <OrganizationBo> > resultList; CultureInfo enCulture = new CultureInfo("en-US"); long organizationId = 0; if (filterCriteria == null) { filterCriteria = new FilterCriteria(); } DictonaryFilter dictonaryFilter = filterCriteria.DictonaryBasedFilter.FirstOrDefault(x => x.Key == "organizationId"); if (dictonaryFilter == null || !long.TryParse(dictonaryFilter.Data, out organizationId)) { organizationId = 0; } if (organizationId > 0) { // Yetki kontrolü yapılıyor ServiceResult <bool> resultAutorized = await GetAutorizedOrganizationStatusById(organizationId); if (!resultAutorized.Success || !resultAutorized.Data) { return(GenericResponse <IEnumerable <OrganizationDto> > .Error(ResultType.Error, "Not Autorized Access!", "O_GL_01", StatusCodes.Status203NonAuthoritative)); } } else { ServiceResult <UserBo> userDtoResult = await GetCurrentUser(); if (!userDtoResult.Success || userDtoResult.Data == null) { return(GenericResponse <IEnumerable <OrganizationDto> > .Error(ResultType.Error, "User Not Found!", "O_GL_02", StatusCodes.Status404NotFound)); } organizationId = userDtoResult.Data.OrganizationId; } resultList = await serviceManager.Organization_Service.GetHierarchicalyByOrganizationIdAsync(organizationId); if (!resultList.Success || resultList.Data == null) { return(GenericResponse <IEnumerable <OrganizationDto> > .Error(ResultType.Error, resultList.Error, "O_GL_03", StatusCodes.Status500InternalServerError)); } listBo = resultList.Data; foreach (DictonaryFilter item in filterCriteria.DictonaryBasedFilter) { switch (item.Key.ToLower(enCulture)) { case "title": switch (item.OperandType) { case OperandType.Equal: listBo = listBo.Where(x => x.Title.ToLower() == item.Data.ToLower()); break; case OperandType.NotEqual: listBo = listBo.Where(x => x.Title.ToLower() != item.Data.ToLower()); break; case OperandType.Like: listBo = listBo.Where(x => x.Title.ToLower().Contains(item.Data.ToLower())); break; } break; case "description": switch (item.OperandType) { case OperandType.Equal: listBo = listBo.Where(x => x.Description.ToLower() == item.Data.ToLower()); break; case OperandType.NotEqual: listBo = listBo.Where(x => x.Description.ToLower() != item.Data.ToLower()); break; case OperandType.Like: listBo = listBo.Where(x => x.Description.ToLower().Contains(item.Data.ToLower())); break; } break; } } IEnumerable <OrganizationDto> listDto = listBo.Select(x => OrganizationBo.ConvertToDto(x)); return(GenericResponse <IEnumerable <OrganizationDto> > .Ok(listDto)); }