private async Task <ParkObjectViewModel> SaveAsync(int?id, ParkObjectSaveModel model) { var entity = id.HasValue ? await _parkObjectRepository.GetByIdAsync(id.Value) : new ParkObject(); entity.Name = model.Name; entity.AdministrationDescriptionMarkdown = model.AdministrationDescriptionMarkdown; entity.Location = model.Location; entity.ParkId = model.ParkId; entity.PriceForChildren = model.PriceForChildren; entity.PriceForAdults = model.PriceForAdults; entity.PublicDescriptionMarkdown = model.PublicDescriptionMarkdown; entity.ImageUrl = model.ImageUrl; entity.Type = model.Type; entity.WorkScheduleJson = model.WorkScheduleJson; _parkObjectRepository.Save(entity); await _unitOfWork.CommitAsync(); var viewModel = new ParkObjectViewModel { Name = entity.Name, AdministrationDescriptionMarkdown = entity.AdministrationDescriptionMarkdown, Location = entity.Location, ParkId = entity.ParkId, PriceForChildren = entity.PriceForChildren, PriceForAdults = entity.PriceForAdults, PublicDescriptionMarkdown = entity.PublicDescriptionMarkdown, Id = entity.Id, Type = entity.Type, ImageUrl = entity.ImageUrl, WorkScheduleJson = entity.WorkScheduleJson, TicketsTotal = entity.Tickets.Count, TicketsClosed = entity.Tickets.Count(t => t.Closed) }; return(viewModel); }
public async Task <ParkObjectViewModel> UpdateAsync(int id, ParkObjectSaveModel saveModel) { return(await SaveAsync(id, saveModel)); }
public async Task <ParkObjectViewModel> CreateAsync(ParkObjectSaveModel saveModel) { return(await SaveAsync(null, saveModel)); }