public async Task <FarmModel> GetFarmAsync(ClaimsPrincipal claimsPrincipal, FarmFilterModel criterias) { if (criterias == null) { criterias = new FarmFilterModel(); } if (!criterias.Id.HasValue || criterias.Id <= 0) { throw new ArgumentNullException(nameof(criterias.Id)); } try { var farmResult = await _farmService.FindDetailAsync(new IdRequestFilter <long> { Id = criterias.Id.GetValueOrDefault(), CanGetInactived = true }); var currentUserId = GetCurrentUserId(claimsPrincipal); if (currentUserId != farmResult.CreatedById) { throw new UnauthorizedAccessException(); } var farm = await MapFarmResultToModelAsync(farmResult); return(farm); } catch (Exception) { throw; } }
public async Task <FarmPageListModel> GetUserFarmsAsync(ClaimsPrincipal claimsPrincipal, FarmFilterModel criterias) { if (criterias == null) { criterias = new FarmFilterModel(); } if (string.IsNullOrEmpty(criterias.UserIdentityId)) { return(new FarmPageListModel(new List <FarmModel>()) { Filter = criterias }); } var currentUserId = GetCurrentUserId(claimsPrincipal); var userId = await _userManager.DecryptUserIdAsync(criterias.UserIdentityId); var filterRequest = new FarmFilter { Page = criterias.Page, PageSize = criterias.PageSize.HasValue && criterias.PageSize < _pagerOptions.PageSize ? criterias.PageSize.Value : _pagerOptions.PageSize, Keyword = criterias.Search, CreatedById = userId, CanGetInactived = currentUserId == userId }; try { var farmPageList = await _farmService.GetAsync(filterRequest); var farms = await MapFarmsResultToModelAsync(farmPageList.Collections); var farmPage = new FarmPageListModel(farms) { Filter = criterias, TotalPage = farmPageList.TotalPage, TotalResult = farmPageList.TotalResult }; return(farmPage); } catch (Exception) { throw; } }
public async Task <IActionResult> Index(FarmFilterModel filter) { var farmPageList = await _farmService.GetAsync(new FarmFilter { CreatedById = filter.CreatedById, CreatedDateFrom = filter.CreatedDateFrom, CreatedDateTo = filter.CreatedDateTo, Page = filter.Page, PageSize = _pagerOptions.PageSize, Keyword = filter.Search, UpdatedById = filter.UpdatedById, FarmTypeId = filter.FarmTypeId, StatusId = filter.StatusId, CanGetDeleted = true, CanGetInactived = true }); var farms = farmPageList.Collections.Select(x => new FarmModel { Id = x.Id, Name = x.Name, Description = x.Description, CreatedBy = x.CreatedBy, CreatedDate = x.CreatedDate, PictureId = x.Pictures.Any() ? x.Pictures.FirstOrDefault().Id : 0, UpdatedBy = x.UpdatedBy, UpdatedDate = x.UpdatedDate, StatusId = (FarmStatus)x.StatusId }); var farmPage = new PageListModel <FarmModel>(farms) { Filter = filter, TotalPage = farmPageList.TotalPage, TotalResult = farmPageList.TotalResult }; if (_httpHelper.IsAjaxRequest(Request)) { return(PartialView("Partial/_FarmTable", farmPage)); } return(View(farmPage)); }
public async Task <FarmPageListModel> GetFarmsAsync(FarmFilterModel criterias) { if (criterias == null) { criterias = new FarmFilterModel(); } var filterRequest = new FarmFilter() { Page = criterias.Page, PageSize = criterias.PageSize.HasValue && criterias.PageSize < _pagerOptions.PageSize ? criterias.PageSize.Value : _pagerOptions.PageSize, Keyword = criterias.Search }; if (!string.IsNullOrEmpty(criterias.ExclusiveUserIdentityId)) { filterRequest.ExclusiveUserId = await _userManager.DecryptUserIdAsync(criterias.ExclusiveUserIdentityId); } try { var farmPageList = await _farmService.GetAsync(filterRequest); var farms = await MapFarmsResultToModelAsync(farmPageList.Collections); var farmPage = new FarmPageListModel(farms) { Filter = criterias, TotalPage = farmPageList.TotalPage, TotalResult = farmPageList.TotalResult }; return(farmPage); } catch (Exception) { throw; } }
public async Task <bool> DeleteFarmAsync(ClaimsPrincipal claimsPrincipal, FarmFilterModel criterias) { try { if (!criterias.Id.HasValue || criterias.Id <= 0) { throw new ArgumentNullException(nameof(criterias.Id)); } var exist = await _farmService.FindAsync(new IdRequestFilter <long> { Id = criterias.Id.GetValueOrDefault(), CanGetInactived = true }); if (exist == null) { return(false); } var currentUserId = GetCurrentUserId(claimsPrincipal); if (currentUserId != exist.CreatedById) { throw new UnauthorizedAccessException(); } return(await _farmService.SoftDeleteAsync(new FarmModifyRequest { UpdatedById = currentUserId, Id = criterias.Id.GetValueOrDefault() })); } catch (Exception) { throw; } }
public async Task <bool> DeleteFarmAsync(ClaimsPrincipal claimsPrincipal, [Service] IFarmResolver farmResolver, FarmFilterModel criterias) { return(await farmResolver.DeleteFarmAsync(claimsPrincipal, criterias)); }
public async Task <FarmPageListModel> GetFarmsAsync([Service] IFarmResolver farmResolver, FarmFilterModel criterias) { return(await farmResolver.GetFarmsAsync(criterias)); }
public async Task <FarmPageListModel> GetUserFarmsAsync(ClaimsPrincipal claimsPrincipal, [Service] IFarmResolver farmResolver, FarmFilterModel criterias) { return(await farmResolver.GetUserFarmsAsync(claimsPrincipal, criterias)); }