Beispiel #1
0
 public static Speaker Extend(this Speaker original, SpeakerVm speaker)
 // todo: allow empty fields (when possible)
 => new Speaker
 {
     ExportId = speaker.Id,
     Name     = string.IsNullOrWhiteSpace(speaker.Name)
             ? original.Name
             : speaker.Name,
     CompanyName = string.IsNullOrWhiteSpace(speaker.CompanyName)
             ? original.CompanyName
             : speaker.CompanyName,
     CompanyUrl = string.IsNullOrWhiteSpace(speaker.CompanyUrl)
             ? original.CompanyUrl
             : speaker.CompanyUrl,
     Description = string.IsNullOrWhiteSpace(speaker.Description)
             ? original.Description
             : speaker.Description,
     BlogUrl = string.IsNullOrWhiteSpace(speaker.BlogUrl)
             ? original.BlogUrl
             : speaker.BlogUrl,
     ContactsUrl = string.IsNullOrWhiteSpace(speaker.ContactsUrl)
             ? original.ContactsUrl
             : speaker.ContactsUrl,
     TwitterUrl = string.IsNullOrWhiteSpace(speaker.TwitterUrl)
             ? original.TwitterUrl
             : speaker.TwitterUrl,
     HabrUrl = string.IsNullOrWhiteSpace(speaker.HabrUrl)
             ? original.HabrUrl
             : speaker.HabrUrl,
     GitHubUrl = string.IsNullOrWhiteSpace(speaker.GitHubUrl)
             ? original.GitHubUrl
             : speaker.GitHubUrl,
 };
        public async Task <SpeakerVm> AddSpeakerAsync(SpeakerVm speaker)
        {
            var result = await _speakerService.AddSpeakerAsync(speaker).ConfigureAwait(false);

            _cache.Remove(nameof(GetAllSpeakersAsync));

            return(result);
        }
Beispiel #3
0
        public async Task <SpeakerVm> UpdateSpeakerAsync(SpeakerVm speaker)
        {
            speaker.EnsureIsValid();
            var original = await _speakerProvider.GetSpeakerOrDefaultAsync(speaker.Id).ConfigureAwait(false);

            var res = await _speakerProvider.SaveSpeakerAsync(original.Extend(speaker)).ConfigureAwait(false);

            return(res.ToVm(res.GetLastUpdateDate(_settings)));
        }
        public async Task <SpeakerVm> UpdateSpeakerAsync(SpeakerVm speaker)
        {
            var result = await _speakerService.UpdateSpeakerAsync(speaker).ConfigureAwait(false);

            _cache.Remove(nameof(GetAllSpeakersAsync));
            if (_cache.TryGetValue <List <AutocompleteRow> >(nameof(GetAllSpeakersAsync), out var speakers))
            {
                speakers.ForEach(x => _cache.Remove($"{nameof(GetSpeakerAsync)}_{x.Id}"));
            }

            return(result);
        }
Beispiel #5
0
        public static SpeakerVm EnsureIsValid(this SpeakerVm speaker)
        {
            // todo: implement full validation
            if (string.IsNullOrWhiteSpace(speaker.Name))
            {
                throw new FormatException(nameof(speaker.Name));
            }

            if (string.IsNullOrWhiteSpace(speaker.Description))
            {
                throw new FormatException(nameof(speaker.Description));
            }

            return(speaker);
        }
Beispiel #6
0
        public async Task <SpeakerVm> AddSpeakerAsync(SpeakerVm speaker)
        {
            speaker.EnsureIsValid();

            var original = await _speakerProvider.GetSpeakerOrDefaultAsync(speaker.Id).ConfigureAwait(false);

            if (original != null)
            {
                throw new FormatException($"Данный {nameof(speaker.Id)} \"{speaker.Id}\" уже занят");
            }

            var entity = new Speaker {
                Id = speaker.Id
            }.Extend(speaker);
            var res = await _speakerProvider.SaveSpeakerAsync(entity).ConfigureAwait(false);

            return(res.ToVm(res.GetLastUpdateDate(_settings)));
        }
Beispiel #7
0
        public async Task <SpeakerVm> UpdateSpeakerAsync(SpeakerVm speaker)
        {
            speaker.EnsureIsValid();
            var original = await _speakerProvider.GetSpeakerOrDefaultAsync(speaker.Id).ConfigureAwait(false);

            original.ExportId       = speaker.Id;
            original.Name           = speaker.Name;
            original.CompanyName    = speaker.CompanyName;
            original.CompanyUrl     = speaker.CompanyUrl;
            original.Description    = speaker.Description;
            original.BlogUrl        = speaker.BlogUrl;
            original.ContactsUrl    = speaker.ContactsUrl;
            original.HabrUrl        = speaker.HabrUrl;
            original.TwitterUrl     = speaker.TwitterUrl;
            original.GitHubUrl      = speaker.GitHubUrl;
            original.LastUpdateDate = DateTime.UtcNow;

            await _unitOfWork.SaveChangesAsync();

            return(original.ToVm());
        }
Beispiel #8
0
 public Task <SpeakerVm> UpdateSpeaker([FromBody] SpeakerVm speaker)
 => _speakerService.UpdateSpeakerAsync(speaker);
Beispiel #9
0
 public Task <SpeakerVm> AddSpeaker([FromBody] SpeakerVm speaker)
 => _speakerService.AddSpeakerAsync(speaker);