public async Task <int> AddRoasterAsync(Roaster roaster, string tags, Address address, string latitude, string longitude, IFormFile picture) { try { _logger.Information("Roaster admin service layer access in progress..."); var roasterByName = await _roasterRepository.GetRoasterByNameNonTrackableAsync(roaster.Name); if (roasterByName != null) { return(-1); } //Get and process tags string into tag entities var _localTags = await RoasterAdminServiceBuilder.BuildTagsListAsync(tags, _tagRepository); //process address entity var _address = Address.New(address.AddressStr, address.OpeningHours, address.Latitude, address.Longitude); address = AddressCoordinatesTransformer.ConvertCoordinates(address, latitude, longitude); roaster.OfficeAddress = _address; _addressReposiotry.Add(_address); //add roasterTags notes RoasterTagsPairsBuilder.BuildRoasterTags(_localTags, roaster.Id, _roasterTagRepository); var pictureBytes = BytePictureBuilder.GetBytePicture(picture); BytePictureBuilder.BindPicture(roaster.Id, pictureBytes, _pictureRepository); roaster = RoasterAdminServiceBuilder.AddRoasterNullPlugs(roaster); _roasterRepository.Add(roaster); await _roasterRepository.SaveChangesAsync(); _logger.Information($"Roaster, Tags, RoasterTags, Addresses tables have been modified. Inserted roaster:\n Id: {roaster.Id}\n Roaster name: {roaster.Name}"); return(0); } catch (Exception e) { _logger.Error($"Roaster admin service layer error occured! Error text message: {e.Message}"); return(-2); } }
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); } }