コード例 #1
0
        public static BarToEditDTO MapToDTO(this AddBarViewModel bar)
        {
            var dto = new BarToEditDTO
            {
                Name      = bar.Name,
                ImagePath = bar.ImagePath,
                Address   = bar.Address.MapToDTO()
            };

            return(dto);
        }
コード例 #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);
        }
コード例 #3
0
        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();
        }