public void PostNewPartCategoryToDB(CategoryInsertViewModel partCategory) { var partCategoryToInsert = new PartCategory(); partCategoryToInsert.CategoryPart = partCategory.CategoryPart; _partCategoryContext.Insert(partCategoryToInsert); _partCategoryContext.Commit(); _logger.Info("Inserted record Id " + partCategoryToInsert.Id + " into Table " + tableNameUsedByLogger); }
public async Task <ActionResult> Create(CategoryInsertViewModel viewModel) { if (ModelState.IsValid) { viewModel.CreatorId = long.Parse(User.Identity.GetUserId()); await _categoryService.Create(viewModel); ViewBag.Message = "مخاطب جدید با موفقیت ثبت شد."; return(RedirectToAction("Index")); } ViewBag.Message = "ثبت انجام نشد."; return(View(viewModel)); }
public ActionResult Create(CategoryInsertViewModel partCategory) { //if errors found return to view, otherwise insert into DB if (!ModelState.IsValid) { return(View(partCategory)); } else { _partCategoryService.PostNewPartCategoryToDB(partCategory); //Once part category inserted then return to display list of categories return(RedirectToAction("Index")); } }
public JsonResult CreateCategory(CategoryInsertViewModel model) { var errMsg = ""; if (!ModelState.IsValid) { foreach (var modelStateValue in ModelState.Values) { foreach (var error in modelStateValue.Errors) { errMsg += error.ErrorMessage + "\n"; } } return(Json(new ResponseData() { Success = false, Message = "Bir hata oluştu, " + errMsg })); } var category = _categoryRepo.GetAll().FirstOrDefault(x => x.Name == model.Name); if (category == null) { _categoryRepo.Insert(new Category() { Name = model.Name, }); return(Json(new ResponseData() { Data = model.Name, Success = true, Message = "Kategori başarı ile eklenmiştir." })); } else { return(Json(new ResponseData() { Success = false, Message = "Bu isimde bir kategori zaten mevcuttur." })); } }
public async Task <IActionResult> Insert(CategoryInsertViewModel viewModel) { var configuration = new MapperConfiguration(cfg => { cfg.CreateMap <CategoryInsertViewModel, CategoryDTO>(); }); IMapper mapper = configuration.CreateMapper(); // new SERService().GetSERByID(4); //Transforma o ClienteInsertViewModel em um ClienteDTO CategoryDTO dto = mapper.Map <CategoryDTO>(viewModel); try { await _categoryService.Insert(dto); return(RedirectToAction("Index", "Category")); } catch (Exception ex) { ViewBag.Erros = ex.Message; } return(View()); }
public CategoryInsertViewModel CreateNewPartCategoryObject() { var partCategory = new CategoryInsertViewModel(); return(partCategory); }
public async Task Create(CategoryInsertViewModel viewModel) { _category.Add(_mappingEngine.Map <Category>(viewModel)); await _unitOfWork.SaveChangesAsync(); }