public async Task <EntityDto <Guid> > CreateActivityFromActivityTemplate(CreateActivityFromActivityTemplateInput input) { var currentUser = await GetCurrentUserAsync(); var activityTemplate = await _activityTemplateManager.GetAsync(input.ActivityTemplateId); var activity = await _activityManager.CreateAsync(Activity.Create( input.StartTime, input.EndTime, activityTemplate, currentUser )); foreach (var activityTemplateDescription in activityTemplate.Descriptions) { switch (activityTemplateDescription.Type) { case DescriptionType.Text: await _descriptionManager.CreateAsync(TextDescription.Create(((TextDescription)activityTemplateDescription).Text, activity, currentUser.Id)); break; case DescriptionType.ExternalImage: await _descriptionManager.CreateAsync(ExternalImageDescription.Create(((ExternalImageDescription)activityTemplateDescription).Path, activity, currentUser.Id)); break; case DescriptionType.InternalImage: await _descriptionManager.CreateAsync(InternalImageDescription.Create(((InternalImageDescription)activityTemplateDescription).Image, activity, currentUser.Id)); break; case DescriptionType.Youtube: await _descriptionManager.CreateAsync(YoutubeDescription.Create(((YoutubeDescription)activityTemplateDescription).YoutubeId, activity, currentUser.Id)); break; default: throw new ArgumentOutOfRangeException(); } } return(new EntityDto <Guid>(activity.Id)); }
public async Task <EntityDto <long> > CreateTextDescription(CreateTextDescriptionInput input) { var currentUserId = GetCurrentUserId(); Description textDescription; if (input.ActivityId.HasValue) { var activity = await _activityManager.GetAsync(input.ActivityId.Value); textDescription = await _descriptionManager.CreateAsync(TextDescription.Create(input.Text, activity, currentUserId)); } else if (input.ActivityTemplateId.HasValue) { var activityTemplate = await _activityTemplateManager.GetAsync(input.ActivityTemplateId.Value); textDescription = await _descriptionManager.CreateAsync(TextDescription.Create(input.Text, activityTemplate, currentUserId)); } else if (input.ActivityPlanId.HasValue) { var activityPlan = await _activityPlanManager.GetAsync(input.ActivityPlanId.Value); textDescription = await _descriptionManager.CreateAsync(TextDescription.Create(input.Text, activityPlan, currentUserId)); } else { throw new UserFriendlyException(""); } return(new EntityDto <long>(textDescription.Id)); }