예제 #1
0
        public async Task <IActionResult> Create(FruitViewModel fruit)
        {
            if (!ModelState.IsValid)
            {
                return(View(fruit));
            }

            if (fruit.ImageUpload != null)
            {
                string prefix = Guid.NewGuid() + "_";

                if (!await UploadImage(fruit.ImageUpload, prefix))
                {
                    return(View(fruit));
                }

                fruit.Image = prefix + fruit.ImageUpload.FileName;
            }

            await _fruitService.Add(_mapper.Map <Fruit>(fruit));

            if (!IsValid())
            {
                return(View(fruit));
            }
            TempData["Success"] = "Fruit successfuly added!";
            return(RedirectToAction("Index"));
        }
예제 #2
0
        public async Task <ActionResult> PostFruid([FromBody] FruitViewModel fruitViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(CustomResponse(fruitViewModel));
            }

            await _fruitService.Add(_mapper.Map <Fruit>(fruitViewModel));

            return(CustomResponse(fruitViewModel));
        }
예제 #3
0
        public IActionResult Post([FromBody] FruitDto dto)
        {
            try
            {
                var validRes = new FruitDtoValidation().Validate(dto);
                if (!validRes.IsValid)
                {
                    return(BadRequest(validRes.Errors));
                }

                var id = _fruitService.Add(dto);
                return(Created($"Game: {id}", id));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }
 public void Add()
 {
     _fruitService.Add(new Fruit());
 }
예제 #5
0
 public IActionResult Create(Fruit fruit)
 {
     return(View("Index", _service.Add(fruit)));
 }