/// <summary> /// Метод получает работы типа. /// </summary> public async override Task <IEnumerable <PortfolioDto> > GetTypeWork(string type) { try { if (string.IsNullOrEmpty(type)) { throw new ArgumentNullException(); } // Определяет тип. CommonMethodsService commonMethodsService = new CommonMethodsService(); var isType = commonMethodsService.IdentityType(type); if (isType != null) { var oTypeWorks = await _db.Portfolio.Where(t => t.Category.Equals(isType)).ToListAsync(); // Приводит путь изображений к нужному виду для фронта. foreach (var el in oTypeWorks) { el.Url = el.Url.Insert(0, "/").Replace("wwwroot/", ""); } return(oTypeWorks); } throw new ArgumentNullException(); } catch (ArgumentNullException ex) { throw new ArgumentNullException("Тип работы не передан", ex.Message.ToString()); } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } }
/// <summary> /// Метод получает данные услуги. /// </summary> /// <returns></returns> public async override Task <OrderDetailDto> GetOrderDetail(string order) { try { // Если нет названия услуги. if (string.IsNullOrEmpty(order)) { throw new ArgumentNullException(); } CommonMethodsService commonMethodsService = new CommonMethodsService(); var isType = commonMethodsService.IdentityType(order); if (isType != null) { return(await _db.OrdersDetails.Where(o => o.OrderName.Equals(isType)).FirstOrDefaultAsync()); } throw new ArgumentNullException(); } catch (ArgumentNullException ex) { throw new ArgumentNullException("Не передано название услуги", ex.Message.ToString()); } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } }
/// <summary> /// Метод создает новую заявку. /// </summary> public async override Task CreateRequest(RequestDto requestDto) { try { if (string.IsNullOrEmpty(requestDto.Name) || string.IsNullOrEmpty(requestDto.EmailOrNumber) || string.IsNullOrEmpty(requestDto.Comment)) { throw new ArgumentNullException(); } // Отправляет на email. CommonMethodsService commonMethodsService = new CommonMethodsService(); await commonMethodsService.SendMessageToEmail(requestDto); // Сохраняет заявку. await _db.Requests.AddRangeAsync(requestDto); await _db.SaveChangesAsync(); } catch (ArgumentNullException ex) { throw new ArgumentNullException("Обязательные поля не заполнены", ex.Message.ToString()); } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } }