Ejemplo n.º 1
0
        public IHttpActionResult AddPizza(string name)
        {
            try
            {
                Core.Core core  = new Core.Core();
                var       pizza = core.GetPizza(name);
                bool      result;

                if (pizza == null)
                {
                    result = core.AddPizza(new Pizza()
                    {
                        Name = name
                    });
                }
                else
                {
                    throw new DuplicateElementException(name);
                }

                return(Content(HttpStatusCode.Created, new { Code = (int)HttpStatusCode.Created, Message = "Pizza successfully added" }));
            }
            catch (DuplicateElementException dex)
            {
                return(Content(HttpStatusCode.Conflict, new { Code = (int)HttpStatusCode.Conflict, Message = dex.Message }));
            }
            catch (Exception ex)
            {
                return(Content(HttpStatusCode.InternalServerError, new { Code = (int)HttpStatusCode.InternalServerError, Message = ex.Message }));
            }
        }