public async Task <IActionResult> AddRoasterRequest([FromBody] RoasterRequest roasterRequest) { try { var roasterrequest = RoasterRequest.New(roasterRequest.Roaster, roasterRequest.Address, roasterRequest.TagString); roasterrequest.Picture = PictureRequest.New(roasterrequest.Picture.Bytes); _roasterRequestRepository.Add(roasterRequest); await _roasterRequestRepository.SaveChangesAsync(); return(Ok()); } catch (Exception e) { return(BadRequest($"{e.Message}")); } }
public async Task <int> BindToRoasterNdAddressAsync(Guid id) { try { _logger.Information("Roaster request service layer access in progress..."); var request = await _roasterRequestRepository.GetSingleAsync(id); var bindTags = await RoasterRequestServiceBuilder.BuildAndBindTags(request.TagString, _tagRepository); var address = Address.New(request.Address.AddressStr, request.Address.OpeningHours, request.Address.Latitude, request.Address.Longitude); var roaster = RoasterRequestServiceBuilder.GenerateRoaster(request.Roaster); roaster.OfficeAddress = address; _addressRepository.Add(address); BytePictureBuilder.BindPicture(roaster.Id, request.Picture.Bytes, _pictureRepository); _roasterRepository.Add(roaster); RoasterTagsPairsBuilder.BuildRoasterTags(bindTags, roaster.Id, _roasterTagRepository); _pictureRequestRepository.Delete(request.Picture); _roasterRequestRepository.Delete(request); await _roasterRequestRepository.SaveChangesAsync(); _logger.Information($"Roaster requests table has been modified. Roaster request:\n Id:{request.Id}"); return(0); } catch (Exception e) { _logger.Error($"Roaster request service layer error occured! Error text message: {e.Message}"); return(-1); } }