public IActionResult Get(string makename, string modelname)
        {
            ModelCar model = _modelRepo.GetModelByName(modelname);

            if (model == null)
            {
                return(NotFound());
            }
            if (model.Make.Name != makename)
            {
                return(BadRequest("there is no model for this make"));
            }
            return(Ok(_mapper.Map <ModelCarViewModel>(model)));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Post(string makename, string modelname, [FromBody] AdvertiseViewModel model)
        {
            try
            {
                var modelCar = _modelCarRepo.GetModelByName(modelname);
                if (modelCar == null)
                {
                    return(BadRequest("No add for this modelname"));
                }

                var advertise = _mapper.Map <Advertise>(model);
                advertise.ModelCar  = modelCar;
                advertise.DateAdded = DateTime.Now;
                //advertise.DateUpdated = DateTime.Now;
                var personWhoAdded = await _usrMgr.FindByNameAsync(this.User.Identity.Name);

                if (personWhoAdded != null)
                {
                    advertise.UserWhoAdded = personWhoAdded.UserName;
                    _advertiseRepo.Add(advertise);

                    if (await _advertiseRepo.SaveAllAsync())
                    {
                        return(Created(Url.Link("GetAdvertise", new { makename = makename, modelname = modelname, id = advertise.Id }),
                                       _mapper.Map <AdvertiseViewModel>(advertise)));
                    }
                }
            }
            catch
            {
            }

            return(BadRequest("Failed to save new talk"));
        }