Ejemplo n.º 1
0
        public IActionResult SupplementAdd()
        {
            SupplementAddVİewModel supplementAddVIewModel = new SupplementAddVİewModel
            {
                Supplement = new Supplement(),
                SupplementSubCategories = _supplementSubCategoryService.GetAll(),
                SupplementCategories    = _supplementCategoryService.GetAll(),
            };

            return(View(supplementAddVIewModel));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> SupplementAdd(Supplement supplement, IFormFile formFile)
        {
            supplement.Time = DateTime.Today;
            if (formFile.Length == 0 && formFile == null)
            {
                TempData.Add("message", "Image not selected");
                return(RedirectToAction("SupplementAdd"));
            }
            else
            {
                using (var stream = new MemoryStream())
                {
                    await formFile.CopyToAsync(stream);

                    supplement.Image = stream.ToArray();
                }
            }
            var errors = ModelState.Values.SelectMany(v => v.Errors);

            if (ModelState.IsValid)
            {
                _supplementService.Add(supplement);
                TempData.Add("message", "Supplement successfully added");
                return(RedirectToAction("SupplementAdd"));
            }
            else
            {
                TempData.Add("message", "Supplement not added");
                SupplementAddVİewModel supplementAddVIewModel = new SupplementAddVİewModel
                {
                    Supplement = supplement,
                    SupplementSubCategories = _supplementSubCategoryService.GetAll(),
                    SupplementCategories    = _supplementCategoryService.GetAll()
                };
                return(View(supplementAddVIewModel));
            }
        }