예제 #1
0
 public ActionResult Create(AwardCreateVM model)
 {
     ViewBag.Breadcrumb = new Breadcrumb("award", "create", null);
     try
     {
         if (ModelState.IsValid)
         {
             var award = awardDm.Save(model);
             if (award == null)
             {
                 ModelState.AddModelError("", "Ошибка при сохранении");
                 return(View());
             }
             else
             {
                 return(RedirectToAction("Index"));
             }
         }
         else
         {
             return(View());
         }
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("", $"{ex.Message}");
         return(View());
     }
 }
예제 #2
0
 public IHttpActionResult Post([FromBody] AwardCreateVM award)
 {
     if (award == null)
     {
         return(BadRequest("Award should be defined in request body"));
     }
     if (!ModelState.IsValid)
     {
         return(BadRequest("Award not valid"));
     }
     else
     {
         var awardWithID = awardDm.Save(award);
         if (awardWithID != null)
         {
             return(Created($"api/user/{awardWithID.ID}", awardWithID));
         }
         else
         {
             return(BadRequest());
         }
     }
 }