Esempio n. 1
0
        public async Task <IActionResult> Insert(FoodViewModel vm)
        {
            if (ModelState.IsValid)
            {
                if (User.IsInRole("Admin"))
                {
                    vm.IsGlobal = true;
                }
                else if (User.IsInRole("User"))
                {
                    vm.IsGlobal = false;
                }
                vm.Calories  = 0;
                vm.ProfileId = (await _uManager.FindByNameAsync(User.Identity.Name)).ProfileId;
                var f = vm.ToFood();
                var createOperation = await _fbo.CreateAsync(f);

                if (!createOperation.Success)
                {
                    return(View("Error", new ErrorViewModel()
                    {
                        RequestId = createOperation.Exception.Message
                    }));
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(RedirectToAction("Index"));
        }
Esempio n. 2
0
        public ActionResult Create([FromBody] FoodViewModel fvm)
        {
            var f   = fvm.ToFood();
            var res = _bo.Create(f);

            return(StatusCode(res.Success ? (int)HttpStatusCode.OK : (int)HttpStatusCode.InternalServerError));
        }