public async Task <IActionResult> Create([FromBody] ModelCreateDTO modelDTO) { try { if (modelDTO == null) { return(BadRequest(ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var model = _mapper.Map <Model>(modelDTO); var isSuccess = await _modelRepository.Create(model); if (!isSuccess) { return(InternalError($"Creation failed")); } return(Created("Create", new { model })); } catch (Exception e) { return(InternalError($"{e.Message} - {e.InnerException}")); } }
public async Task <IActionResult> Create() { BaseModel model = new BaseModel(); await _modelRepository.Create(model); return(new OkObjectResult(model)); }
public ActionResult Ping() { var model = new Model(); var modelOut = modelRepository.Create(model); return(Ok(modelOut)); }
public void Create(Model model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } modelRepository.Create(model); }
public async Task <ActionResult> Create(CreateModelVM model) { try { if (!ModelState.IsValid) { return(View(model)); } var carModel = _mapper.Map <Model>(model); var makes = await _makeRepo.FindAll(); var makeItems = makes.Select(q => new SelectListItem { Text = q.Title, Value = q.Id.ToString() }); model.MakelList = makeItems; var isExists = await _repo.isExist(carModel.Title, carModel.MakeId); if (isExists) { ModelState.AddModelError("", "This model already exist"); return(View(model)); } var isSuccess = await _repo.Create(carModel); if (!isSuccess) { ModelState.AddModelError("", "Something went wrong..."); return(View(model)); } return(RedirectToAction(nameof(Index))); } catch { return(View(model)); } }
public ActionResult Models(string ModelName, int MakeId) { IModelRepository repo = RepoFactory.CreateModelRepo(); IMakeRepository makerepo = RepoFactory.CreateMakeRepo(); if (ModelName != null && MakeId != 0) { var model = new Model() { DateAdded = DateTime.Today, Name = ModelName, MakeId = MakeId, UserId = System.Web.HttpContext.Current.User.Identity.GetUserId() }; repo.Create(model); } AdminModelViewModel viewModel = new AdminModelViewModel(); viewModel.Models = repo.GetAll().ToList(); viewModel.Makes = makerepo.GetAll().ToList(); return(View(viewModel)); }