Пример #1
0
        public async Task Delete(int id)
        {
            var genre = await genresRepository.GetByIdWithDeletedAsync(id);

            if (genre == null)
            {
                throw new InvalidOperationException("The genre could not be found");
            }

            genresRepository.Delete(genre);
            await genresRepository.SaveChangesAsync();
        }
        public async Task Delete(int id)
        {
            var review = await reviewsRepository.GetByIdWithDeletedAsync(id);

            if (review == null)
            {
                throw new InvalidOperationException("The review could not be found");
            }

            reviewsRepository.Delete(review);
            await reviewsRepository.SaveChangesAsync();
        }
Пример #3
0
        public async Task <int> UpdateAsync(EditCustomerInputModel input)
        {
            var customer = await customersRepository.GetByIdWithDeletedAsync(input.Id);

            var customerEmails = this.emailsService.GetAll <EmailCreateInputModel>(input.Id);
            var customerPhones = this.phonesServices.GetAll <PhoneCreateInputModel>(input.Id);

            foreach (var email in input.Emails)
            {
                if (email.Id != null &&
                    (email.Email != customerEmails.FirstOrDefault(x => x.Id == email.Id)?.Email ||
                     email.EmailType != customerEmails.FirstOrDefault(x => x.Id == email.Id)?.EmailType))
                {
                    await this.emailsService.UpdateAsync(email);
                }
                else if (email.Email != null && email.Id == null)
                {
                    await this.emailsService.CreateAsync(email.Email, email.EmailType, customer.Id);
                }
            }

            foreach (var phone in input.Phones)
            {
                if (phone.Id != null &&
                    (phone.Phone != customerPhones.FirstOrDefault(x => x.Id == phone.Id)?.Phone ||
                     phone.PhoneType != customerPhones.FirstOrDefault(x => x.Id == phone.Id)?.PhoneType))
                {
                    await this.phonesServices.UpdateAsync(phone);
                }
                else if (phone.Phone != null && phone.Id == null)
                {
                    await this.phonesServices.CreateAsync(phone.Phone, phone.PhoneType, customer.Id);
                }
            }

            await this.addressesService.UpdateAsync(input.Address);

            customer.Title          = input.Title;
            customer.FirstName      = input.FirstName;
            customer.MiddleName     = input.MiddleName;
            customer.LastName       = input.LastName;
            customer.AdditionalInfo = input.AdditionalInfo;
            customer.JobTitle       = input.JobTitle;

            this.customersRepository.Update(customer);

            return(await this.customersRepository.SaveChangesAsync());
        }
Пример #4
0
 public async Task <Order> GetOrderByIdAsync(int orderId)
 {
     return(await orderRepository.GetByIdWithDeletedAsync(orderId));
 }