示例#1
0
        public async Task <IActionResult> Create(Feature viewModel, string[] ShopCategoryFeatures)
        {
            if (User.IsInRole(Roles.Client) || !User.Identity.IsAuthenticated)
            {
                return(NotFound());
            }
            if (ShopCategoryFeatures.Count() == 0)
            {
                ModelState.AddModelError("ShopCategoryFeatures", "Select at least one  category");
            }
            if (ModelState.IsValid)
            {
                await _shopCategoryFeatureService.Add(viewModel, ShopCategoryFeatures);

                var Id = await _productFeatureService.Add(viewModel);

                if (!String.IsNullOrEmpty(Request.Form["continue"]))
                {
                    return(RedirectToAction("Edit", new { Id = Id }));
                }
                if (!String.IsNullOrEmpty(Request.Form["new"]))
                {
                    return(RedirectToAction(nameof(Create)));
                }
                return(RedirectToAction(nameof(Index)));
            }

            return(View(viewModel));
        }
示例#2
0
        public IHttpActionResult Post([FromBody] Feature feature)
        {
            try
            {
                var re      = Request;
                var headers = re.Headers;

                if (headers.Contains("Token"))
                {
                    string token      = headers.GetValues("Token").First();
                    User   loggedUser = _userService.GetFromToken(token);
                    if (loggedUser.Role == UserRoles.ADMIN || loggedUser.Role == UserRoles.SUPERADMIN)
                    {
                        _featureService.Add(feature);
                        return(CreatedAtRoute("DefaultApi", new { id = feature.Id }, feature));
                    }
                    return(BadRequest("Solo los administradores pueden agregar características"));
                }
                return(BadRequest("Debes mandar el Token de sesión en los headers"));
            }
            catch (NoUserWithTokenException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (FeatureNoNameException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (FeatureWithoutTypeException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (FeatureWrongTypeException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (FeatureExistingCombinationException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (NullReferenceException ex)
            {
                return(BadRequest("Debes enviar todos los datos"));
            }
        }
示例#3
0
 public object Save([FromBody] Feature model)
 {
     try
     {
         if (model.Id != 0)
         {
             return(featureService.Update(model));
         }
         else
         {
             return(featureService.Add(model));
         }
     }
     catch (Exception ex)
     {
         return(errorLogService.InsertToErrorLog(ex, MethodBase.GetCurrentMethod().Name, Request.Headers["UserInfo"].ToString()));
     }
 }
 public IActionResult AddFeature([FromBody] Feature entity)
 {
     _featureService.Add(entity);
     _looger.LogInformation("Add Feature Title : " + entity.Title);
     return(Ok());
 }