示例#1
0
        public async Task <int> UpdateAddressAsync(Address entity, string latitude, string longitude)
        {
            try
            {
                entity = AddressCoordinatesTransformer.ConvertCoordinates(entity, latitude, longitude);
                _logger.Information("Address service Layer access in progress...");
                var address = await _addressRepository.GetSingleAsNoTrackingAsync(entity.AddressStr);

                if (address != null && !address.Id.Equals(entity.Id))
                {
                    return(-1);
                }
                if (entity.OpeningHours == null)
                {
                    entity.OpeningHours = "none";
                }
                _addressRepository.Update(entity);
                await _addressRepository.SaveChangesAsync();

                _logger.Information($"Address Table has been modified. Address:\n Address Id: {entity.Id} \n Address string: {entity.AddressStr}\n has been added.");
                return(0);
            }
            catch (Exception e)
            {
                _logger.Error("Address service layer error occured! Error message:" + e.Message);
                return(-2);
            }
        }
        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> UpdateRoasterAsync(Roaster entity, string tags, string latitude, string longitude, IFormFile picture)
        {
            _logger.Information("Roaster admin service layer access in progress...");
            try
            {
                var broast = await _roasterRepository.GetRoasterByNameNonTrackableAsync(entity.Name);

                if (broast != null && !broast.Id.Equals(entity.Id))
                {
                    return(-1);
                }

                await RoasterAdminServiceBuilder.UpdateRoasterTagsAsync(tags,
                                                                        _tagRepository,
                                                                        _roasterTagRepository,
                                                                        entity.Id);

                await BytePictureBuilder.ReplacePicture(entity.Id, picture, _pictureRepository);


                var roasterAddress = await _addressReposiotry.GetSingleAsync(entity.OfficeAddress.Id);

                entity.OfficeAddress = AddressCoordinatesTransformer.ConvertCoordinates(entity.OfficeAddress, latitude, longitude);
                entity.OfficeAddress = RoasterAdminServiceBuilder.UpdateRoasterAddress(roasterAddress, entity.OfficeAddress);
                _addressReposiotry.Update(entity.OfficeAddress);

                entity = RoasterAdminServiceBuilder.AddRoasterNullPlugs(entity);
                _roasterRepository.Update(entity);
                await _roasterTagRepository.SaveChangesAsync();

                _logger.Information($"Roaster, Tags, RoasterTags, Addresses tables have been modified. Updated roaster:\n Id: {entity.Id}\n Roaster name: {entity.Name}");
                return(0);
            }
            catch (Exception e)
            {
                _logger.Error("Roaster admin service layer error occured! Error text message:" + e.Message);
                return(-2);
            }
        }