public async Task <JsonResult> AddSolutionType([Required] SolutionTypeViewModel model) { if (!ModelState.IsValid) { return(JsonModelStateErrors()); } return(await JsonAsync(_crmVocabulariesService.AddSolutionTypeAsync(model))); }
/// <summary> /// Add solution type /// </summary> /// <param name="model"></param> /// <returns></returns> public virtual async Task <ResultModel <Guid> > AddSolutionTypeAsync(SolutionTypeViewModel model) { if (model == null) { return(new InvalidParametersResultModel <Guid>()); } var solutionType = _mapper.Map <SolutionType>(model); await _context.SolutionTypes.AddAsync(solutionType); var result = await _context.PushAsync(); return(result.Map(solutionType.Id)); }
/// <summary> /// Update solution type /// </summary> /// <param name="model"></param> /// <returns></returns> public virtual async Task <ResultModel> UpdateSolutionTypeAsync(SolutionTypeViewModel model) { if (model == null) { return(new InvalidParametersResultModel()); } var solutionType = await _context.SolutionTypes.AsNoTracking() .FirstOrDefaultAsync(x => x.Id == model.Id); if (solutionType == null) { return(new NotFoundResultModel()); } solutionType = _mapper.Map <SolutionType>(model); _context.SolutionTypes.Update(solutionType); await _context.PushAsync(); return(await _context.PushAsync()); }
public ActionResult EditSolutionType(SolutionTypeViewModel solutionType) { if (ModelState.IsValid) { SolutionType type = _solutionTypeService.GetSolutionType(solutionType.ID); type.Type = solutionType.Type.Trim(); try { _solutionTypeService.SaveSolutionType(); } catch (Exception ex) { return(View(solutionType).WithError(ex.Message)); } } else { return(View(solutionType).WithError("Invalid Data")); } return(RedirectToAction("SolutionTypes").WithSuccess("Solution type " + solutionType.Type + " updated successfully.")); }
public ActionResult CreateSolutionType(SolutionTypeViewModel solutionType) { if (ModelState.IsValid) { SolutionType newType = new SolutionType(); newType.Type = solutionType.Type.Trim(); newType.DateCreated = DateTime.Now; try { _solutionTypeService.CreateSolutionType(newType); _solutionTypeService.SaveSolutionType(); } catch (Exception ex) { return(View(solutionType).WithError(ex.Message)); } } else { return(View(solutionType).WithError("Invalid data")); } return(RedirectToAction("SolutionTypes").WithSuccess("Solution type" + solutionType.Type + " created successfully.")); }