public IHttpActionResult Get(Guid?id)
 {
     try
     {
         ToppingBindingModel model = this.topping.GetTopping(id.GetValueOrDefault());
         return(Ok(model));
     }
     catch (BadRequestException bre)
     {
         ModelState.AddModelError(CommonConstants.ErrorKey, bre.Message);
         return(BadRequest(ModelState));
     }
 }
Пример #2
0
        public ToppingBindingModel GetTopping(Guid id)
        {
            ToppingBindingModel model = Database
                                        .Toppings
                                        .Where(t => t.Id == id)
                                        .Select(t => new ToppingBindingModel {
                Name = t.Name
            })
                                        .FirstOrDefault();

            if (model == null)
            {
                throw new NotExistingEntryException(string.Format(CommonConstants.NotExistingEntry, nameof(Topping)));
            }

            return(model);
        }
        public IHttpActionResult Post([FromBody] ToppingBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                this.topping.Create(model.Name);
                return(Ok(string.Format(CommonConstants.SuccessfullEntityOperation, nameof(Topping), CommonConstants.Created)));
            }
            catch (BadRequestException bre)
            {
                ModelState.AddModelError(CommonConstants.ErrorKey, bre.Message);
                return(BadRequest(ModelState));
            }
        }