public ZoneValidationRequest CreateModifyZoneRequest( ZoneValidationRequest zoneValidationRequest, string requestPersonId) { var dbZone = _zoneService.GetZoneById(zoneValidationRequest.TargetZoneId); if (dbZone == null) { throw new ArgumentOutOfRangeException(nameof(dbZone.Id), "Invalid ZoneId."); } if (dbZone.OwnerId != requestPersonId) { throw new ArgumentOutOfRangeException(nameof(dbZone.Id), "You haven't permissions to modify this zone."); } var zoneRequests = _zoneValidationRequestRepository.FindByZoneId(dbZone.Id); if (zoneRequests.Any(x => x.Status < ZoneValidationStatus.Declined)) { throw new ArgumentOutOfRangeException(nameof(dbZone.Id), "Cannot add modifying request while has another active one for this zone."); } zoneValidationRequest.RequesterId = requestPersonId; return(_zoneValidationRequestRepository.Add(zoneValidationRequest)); }
public List <Product> GetProductsByCriteria(GetProductBySearchTypeDto getProductBySearchTypeDto) { IEnumerable <ProductDto> productDtos = new List <ProductDto>(); if (getProductBySearchTypeDto == null) { return(new List <Product>()); } switch (getProductBySearchTypeDto.ProductSearchTypeId) { case 1: productDtos = _productDao.GetAllProducts(); break; case 2: productDtos = _productDao.GetAllActiveProductsWithStatus(new ProductStatus().Active.Id); break; case 3: if (getProductBySearchTypeDto.ExtraParams == null || !getProductBySearchTypeDto.ExtraParams.ContainsKey("ZoneId")) { productDtos = new List <ProductDto>(); break; } var zones = _zoneService.GetAllChildZones(int.Parse(getProductBySearchTypeDto.ExtraParams["ZoneId"])); productDtos = _productDao.GetAllActiveProductsForZones(zones.Select(x => x.ToDto()).ToList()); break; case 4: productDtos = _productDao.GetAllActiveProductsWithStatus(new ProductStatus().Missing.Id); break; default: productDtos = new List <ProductDto>(); break; } List <Product> products = new List <Product>(); foreach (var productDto in productDtos) { Product product = Product.FromDto(productDto); product.Zone = _zoneService.GetZoneById(productDto.ZoneId); product.Owner = _ownerService.GetOwnerById(productDto.OwnerId); products.Add(product); } return(products); }
public IActionResult GetById(string id) { if (string.IsNullOrEmpty(id)) { return(BadRequest()); } var zone = _zoneService.GetZoneById(id, q => q.Include(x => x.MapRectangle)); // TODO: Try to replace with this line and pass it to the Json(): // new JsonSerializerSettings().ReferenceLoopHandling = ReferenceLoopHandling.Ignore zone.MapRectangle.Zone = null; return(Json(zone)); }
public Task <AreaFilter> CreateAsync(AreaFilter entity, string areaId) { var area = _zoneService.GetZoneById(areaId, x => x.Include(z => z.Settings)); if (area == null) { return(null); } entity.ZoneSettingsId = area.Settings.Id; var newFilter = _areaFilterRepository.Add(entity); return(Task.FromResult(newFilter)); }
public async Task <IActionResult> GetUserRequests(ZoneValidationStatus requestStatus) { var currentIdentityUser = await _userManager.GetUserAsync(User); var currentPersonId = currentIdentityUser.PersonId; var userRequests = _zoneValidationRequestService.GetUserZoneRequests(currentPersonId, requestStatus); var userRequestsListItems = Mapper.Map <ICollection <ZoneValidationRequestListItemViewModel> >(userRequests); foreach (var vm in userRequestsListItems.Where(x => !string.IsNullOrEmpty(x.TargetZoneId))) { var zone = _zoneService.GetZoneById(vm.TargetZoneId); vm.ZoneName = zone.Name; } return(Json(userRequestsListItems)); }
public IActionResult GetZoneById(string id) { var zone = _zoneService.GetZoneById(id); if (zone != null) { return(Ok(new { code = 1, msg = "成功", data = zone })); } return(Ok(new { code = 0, msg = "失败" })); }
public IActionResult GetById(string id) { if (string.IsNullOrEmpty(id)) { return(BadRequest()); } var zone = _zoneService.GetZoneById(id, q => q.Include(x => x.MapRectangle)); // TODO: Try to replace with this line and pass it to the Json(): // new JsonSerializerSettings().ReferenceLoopHandling = ReferenceLoopHandling.Ignore zone.MapRectangle.Zone = null; var viewModel = Mapper.Map <ZoneDetailedViewModel>(zone); var zoneValidationRequest = _zoneValidationRequestService.GetActiveZoneRequest(zone.Id); viewModel.ValidationRequestId = zoneValidationRequest?.Id; return(Json(viewModel)); }