コード例 #1
0
        public IHttpActionResult DeleteTopping(string name)
        {
            try
            {
                Core.Core core    = new Core.Core();
                var       topping = core.GetTopping(name);

                if (topping == null)
                {
                    throw new NullReferenceException("Topping Not Found");
                }

                bool result = core.DeleteTopping(topping);
                if (result)
                {
                    return(Content(HttpStatusCode.OK, new { Code = (int)HttpStatusCode.OK, Message = "Topping successfully deleted" }));
                }
                else
                {
                    return(Content(HttpStatusCode.Conflict, new { Code = (int)HttpStatusCode.Conflict, Message = "Topping could not be deleted" }));
                }
            }
            catch (NullReferenceException nex)
            {
                return(Content(HttpStatusCode.NotFound, new { Code = (int)HttpStatusCode.NotFound, Message = nex.Message }));
            }
            catch (Exception ex)
            {
                return(Content(HttpStatusCode.InternalServerError, new { Code = (int)HttpStatusCode.InternalServerError, Message = ex.Message }));
            }
        }