public async Task <ActionResult <GroupZoneResponse> > PostGroupZone([FromBody] GroupZoneRequest model) { int brandId = Convert.ToInt32(User.FindFirst("BrandId")?.Value); var rs = await _groupZoneServices.PostGroupZone(model, brandId); return(Ok(rs)); }
public async Task <GroupZoneResponse> PostGroupZone(GroupZoneRequest model, int brandId) { try { List <Geometry> geoms; if (model.Type == (int)GroupZoneType.Ward) { geoms = await _unitOfWork.Repository <Ward>().GetAll().Where(x => model.ListZoneId.Any(c => c == x.Id)).Select(x => x.Geom).ToListAsync(); } else if (model.Type == (int)GroupZoneType.District) { geoms = await _unitOfWork.Repository <District>().GetAll().Where(x => model.ListZoneId.Any(c => c == x.Id)).Select(x => x.Geom).ToListAsync(); } else { geoms = await _unitOfWork.Repository <SystemZone>().GetAll().Where(x => model.ListZoneId.Any(c => c == x.Id)).Select(x => x.Geom).ToListAsync(); } Geometry groupZoneGeom = (geoms.Any()) ? GeoJsonHelper.CombineGeoCollection(geoms) : null; var insertItem = new GroupZone() { BrandId = brandId, Geom = groupZoneGeom, Name = model.Name, }; await _unitOfWork.Repository <GroupZone>().InsertAsync(insertItem); await _unitOfWork.CommitAsync(); return(new GroupZoneResponse() { Id = insertItem.Id, Geom = insertItem.Geom, BrandId = insertItem.BrandId, Name = insertItem.Name }); } catch (Exception e) { throw new CrudException(HttpStatusCode.BadRequest, "Insert Groupzone Error!!!", e.InnerException?.Message); } }