Пример #1
0
 public void Update(Guid id, Product product)
 {
     if (product == null || product.Name == null)
     {
         string errMessage = product == null ? "Product cannot be null." : "Product name cannot be null.";
         var    response   = HttpResponseFactory.ConstructResponse(HttpStatusCode.BadRequest, errMessage);
         throw new HttpResponseException(response);
     }
     _productsService.UpdateProduct(id, product);
 }
 public Person Update(int id, Person person)
 {
     if (person == null)
     {
         string errMessage = "Person cannot be null.";
         var    response   = HttpResponseFactory.ConstructResponse(HttpStatusCode.BadRequest, errMessage);
         throw new HttpResponseException(response);
     }
     return(_ageRangerService.UpdatePerson(id, person));
 }
Пример #3
0
 public void UpdateOption(Guid id, ProductOption option)
 {
     if (option == null || option.Name == null)
     {
         string errMessage = option == null ? "Option cannot be null." : "Option name cannot be null.";
         var    response   = HttpResponseFactory.ConstructResponse(HttpStatusCode.BadRequest, errMessage);
         throw new HttpResponseException(response);
     }
     _productsService.UpdateOption(id, option);
 }
 public void Delete(int id)
 {
     try
     {
         _ageRangerService.DeletePerson(id);
     } catch (Exception)
     {
         var response = HttpResponseFactory.ConstructResponse(HttpStatusCode.BadRequest, "Delete failed, please try again.");
         throw new HttpResponseException(response);
     }
 }
 public void Create(Person person)
 {
     try
     {
         _ageRangerService.AddPerson(person);
     }catch (Exception)
     {
         var response = HttpResponseFactory.ConstructResponse(HttpStatusCode.BadRequest, "Create new person failed, please check your input.");
         throw new HttpResponseException(response);
     }
 }
Пример #6
0
 public void Delete(Guid id)
 {
     try
     {
         _productsService.DeleteProduct(id);
     } catch (Exception)
     {
         var response = HttpResponseFactory.ConstructResponse(HttpStatusCode.BadRequest, "Delete failed, please try again.");
         throw new HttpResponseException(response);
     }
 }
Пример #7
0
        public ProductOption GetOption(Guid productId, Guid id)
        {
            var option = new ProductOption();

            try
            {
                option = _productsService.GetOptionById(productId, id);
            } catch (Exception)
            {
                var response = HttpResponseFactory.ConstructResponse(HttpStatusCode.BadRequest, string.Format("Product with Id = {0} not found.", productId));
                throw new HttpResponseException(response);
            }
            return(option);
        }
Пример #8
0
 public void CreateOption(Guid productId, ProductOption option)
 {
     if (option == null)
     {
         var response = HttpResponseFactory.ConstructResponse(HttpStatusCode.BadRequest, "Option cannot be null.");
         throw new HttpResponseException(response);
     }
     try
     {
         _productsService.CreateOption(productId, option);
     }
     catch (Exception)
     {
         var response = HttpResponseFactory.ConstructResponse(HttpStatusCode.BadRequest, string.Format("Product with Id = {0} not found.", productId));
         throw new HttpResponseException(response);
     }
 }