Ejemplo n.º 1
0
        public ActionResult AddNewModel(ModelViewModel model, HttpPostedFileBase uploadImage)
        {
            if (ModelState.IsValid)
            {
                if (uploadImage != null)
                {
                    string writePath = Server.MapPath(@"~/Content/Images/Models/") + model.Name + ".jpg";

                    Image img = Image.FromStream(uploadImage.InputStream);

                    img.Save(writePath);

                    model.PhotoUrl = model.Name + ".jpg";
                }

                model.BrandId = (int)TempData.Peek("BrandId");

                try
                {
                    modelService.AddModel(Mapper.Map <ModelViewModel, ModelDTO>(model));
                }
                catch (ValidationException ex)
                {
                    ViewBag.PropertyException = ex.Property;
                    ViewBag.MessageException  = ex.Message;
                    ViewBag.BrandId           = model.BrandId;

                    return(View("ExceptionView"));
                }
            }
            return(RedirectToAction("Models", new RouteValueDictionary(new { controller = "Model", action = "Models", brandId = TempData["BrandId"] })));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> AddModel(AddModelDto newModel)
        {
            ServiceResponse <Model> response = await _modelService.AddModel(newModel);

            if (response.Data == null)
            {
                return(NotFound(response));
            }
            return(Ok(response));
        }
Ejemplo n.º 3
0
        public ActionResult <ModelVM> AddModel([FromBody] ModelDTO modelDTO)
        {
            var model = _mapper.Map <Model>(modelDTO);

            _modelService.AddModel(model);
            _modelService.SaveChanges();
            _log.Save(User.Identity.Name, "Dodano model", GetType().Name);

            return(Ok());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> AddModel([FromBody] ModelDto model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var newModel = _mapper.Map <Model>(model);

            await _modelService.AddModel(newModel);

            return(Ok(_mapper.Map <ModelDto>(newModel)));
        }