public static BarToEditDTO MapToDTO(this AddBarViewModel bar)
        {
            var dto = new BarToEditDTO
            {
                Name      = bar.Name,
                ImagePath = bar.ImagePath,
                Address   = bar.Address.MapToDTO()
            };

            return(dto);
        }
Ejemplo n.º 2
0
        public static AddBarViewModel MapToViewModel(this BarToEditDTO bar)
        {
            var dto = new AddBarViewModel
            {
                Name        = bar.Name,
                ImagePath   = bar.ImagePath,
                PhoneNumber = bar.PhoneNumber,
                Address     = bar.Address.MapToViewModel()
            };

            return(dto);
        }
        public async Task EditAsync(BarToEditDTO newBarInfo)
        {
            if (!await context.Bars.AnyAsync(b => b.Id == newBarInfo.Id && b.IsDeleted == false))
            {
                throw new InvalidOperationException(OutputConstants.InvalidId);
            }

            var bar = await context.Bars
                      .Include(b => b.Address)
                      .Where(b => b.Id == newBarInfo.Id && b.IsDeleted == false)
                      .FirstOrDefaultAsync();

            bar.Name              = newBarInfo.Name;
            bar.ImagePath         = newBarInfo.ImagePath;
            bar.Address.Name      = newBarInfo.Address.Name;
            bar.Address.Latitude  = newBarInfo.Address.Latitude;
            bar.Address.Longitude = newBarInfo.Address.Longitude;
            bar.Address.CityId    = newBarInfo.Address.CityId;

            await context.SaveChangesAsync();
        }