public ActionResult Create(CategoryViewModel categoryViewModel, string submit) { if (ModelState.IsValid) { if (categoryViewModel != null && submit == "Save") { categoryViewModel.DateCreated = DateTime.UtcNow; categoryViewModel.DateModified = DateTime.UtcNow; var category = Mapper.Map <CategoryViewModel, Category>(categoryViewModel); _categoryService.Add(category); AddMessage(this, "", "Record has Added Successfully", MessageType.Success); return(RedirectToAction("Index", "Category")); } if (categoryViewModel != null && submit == "SaveAndContinue") { categoryViewModel.DateCreated = DateTime.UtcNow; categoryViewModel.DateModified = DateTime.UtcNow; var category = Mapper.Map <CategoryViewModel, Category>(categoryViewModel); _categoryService.Add(category); AddMessage(this, "", "Record has Added Successfully", MessageType.Success); ModelState.Clear(); return(View()); } } return(View(categoryViewModel)); }
public ActionResult AddOrEdit(Category category) { if (category.CategoryId == 0) { if (categoryService.Add(category)) { return(Json(new { success = true, message = "Add successfully" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = false, message = "Failed to add" }, JsonRequestBehavior.AllowGet)); } } else { if (categoryService.Edit(category)) { return(Json(new { success = true, message = "Edit successfully" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = false, message = "Failed to edit" }, JsonRequestBehavior.AllowGet)); } } }
public IActionResult Create(Category category) { if (ModelState.IsValid) { _categoryService.Add(category); return(RedirectToAction(nameof(Index))); } return(View()); }
public IActionResult Create(CategoryViewModel categoryViewModel) { var category = new Category(); if (ModelState.IsValid) { category.Name = categoryViewModel.Name; _categoryService.Add(category); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public IActionResult ProductAdd(ProductViewModel model) { if (ModelState.IsValid) { string uniqueFileName = null; if (model.Image != null) { string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "ProductImages"); uniqueFileName = Guid.NewGuid().ToString().Replace("-", "") + "_" + model.Image.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); model.Image.CopyTo(new FileStream(filePath, FileMode.Create)); } Category category; category = categoryService.Get(x => x.id == model.Categoryid, CurrentLanguage.id); if (category == null && model.Categoryid == 0) { Category rootCategory = categoryService.Get(x => x.Name == "ROOT" && x.WebSite.id == CurrentWebsite.id, CurrentLanguage.id); if (rootCategory == null) { rootCategory = new Category() { Name = "ROOT", Parentid = 0, WebSite = CurrentWebsite, Language = CurrentLanguage, Priority = int.MaxValue }; categoryService.Add(rootCategory); categoryService.Save(); } category = rootCategory; } Product product = new Product() { SupTitle = model.SupTitle, SubTitle = model.SubTitle, Category = category, PhotoPath = uniqueFileName, Description = model.Description, MetaTags = model.MetaTags, Keywords = model.Keywords, Content = model.Content, Title = model.Title, CreateUserid = LoginUser.id, IsActive = model.IsActive, Language = CurrentLanguage, Priority = model.Priority }; productService.Add(product); productService.Save(); } return(RedirectToAction("ProductAdd", "Pages", new { area = "Admin" })); }
public ActionResult <AddModel <CategoryModel> > Add() { try { return(Ok(_serviceCategory.Add())); } catch (Exception exception) { ModelState.AddModelError("ErrorMessage", exception.Message); return(BadRequest(ModelState)); } }
private void bSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxName.Text)) { MessageBox.Show("Заполните", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { if (copy.HasValue) { CategoryVM toCopy = service.Get(id.Value); CategoryBM original = new CategoryBM { Name = toCopy.Name }; CategoryBM Copyed = original.DeepCopy() as CategoryBM; service.Add(Copyed); } else if (id.HasValue) { service.Update(new CategoryBM { Id = id.Value, Name = textBoxName.Text }); } else { service.Add(new CategoryBM { Name = textBoxName.Text }); } MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public ActionResult <CategoryDto> Add(Category category) { var result = _categoryService.Add(category); return(result.IsSuccess ? Ok(new CategoryDto(result.Value)) : (ActionResult)NotFound()); }
private async void SubmitButton_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(NameBox.Text)) { ShowMessage("Name is required!", "Error"); } else { Category category = new Category() { Name = NameBox.Text }; DbStatus status = await categoryService.Add(category); if (status == DbStatus.EXISTS) { ShowMessage("Already exists!", "Error"); } else { ShowMessage("Successfully added!", "Success"); this.Close(); } } }
public IActionResult Post([FromBody] Category data) { data.isActive = true; var createdCategory = service.Add(data); return(CreatedAtAction("Get", new { id = createdCategory.Data.Id }, createdCategory)); }
public IHttpActionResult AddCategory([FromBody] APIEditedCategoryModel editedCategoryModel) { object jsonObject; if (!ModelState.IsValid) { jsonObject = new { status = 500 }; return(Json(jsonObject)); } CategoryDTO categoryDTO = dataMapper.MapEditedCategoryModelToDTO(editedCategoryModel); bool addSuccessfully = categoryService.Add(categoryDTO); if (!addSuccessfully) { jsonObject = new { status = 500 }; } else { APICategoryModel categoryModel = dataMapper.MapCategoryDTOToModel(categoryDTO); jsonObject = new { status = 200, data = categoryModel }; } return(Json(jsonObject)); }
public void Add() { var newCategory = new ArticleCategory { Name = "Test", Description = "", ModifiedById = null, CompanyId = 1, Resources = new List <ArticleCategoryResource> { new ArticleCategoryResource { Culture = Culture.English, Value = "Test" }, new ArticleCategoryResource { Culture = Culture.Spanish, Value = "Prueba" }, new ArticleCategoryResource { Culture = Culture.Hindi, Value = "pareekshan" } } }; var result = _categoryService.Add(newCategory); Assert.IsNotNull(result); }
public NewspaperMutation(IPostService postRepository, ICategoryService categoryService) { Name = "Newspaper_Mutation"; Field <PostType>( "addPost", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <PostInputType> > { Name = "post", Description = "Bu bir post insert işlemidir (Acıklama yazılabilir)" }), resolve: context => { var post = context.GetArgument <Post>("post"); return(postRepository.Add(post)); } ); Field <CategoryType>( "addCategory", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <CategoryInputType> > { Name = "category", Description = "Category added input" }), resolve: context => { var category = context.GetArgument <Category>("category"); return(categoryService.Add(category)); } ); }
public static int InsertCategoryItem(ICategoryService categorytService, string name) { Category category = new Category(); category.Name = name; return(categorytService.Add(category)); }
private void btnCategorySave_Click(object sender, EventArgs e) { try { var id = ((Category)cmbCategories.SelectedItem).Id; if (id < 0) { _categoryService.Add(new Category() { Name = txtCategory.Text }); MessageBox.Show(@"Category added!"); } else { _categoryService.Update(new Category() { Id = id, Name = txtCategory.Text }); MessageBox.Show(@"Category updated!"); } FillCategoryComboBox(); } catch (Exception exception) { MessageBox.Show(exception.Message); } }
public string Test() { StringBuilder result = new StringBuilder(); Category category = new Category(0) { Name = "TestCat" }; try { result.AppendLine("Beginning test"); result.AppendLine(string.Format("Have {0} row(s)", categoryService.Fetch().Count())); categoryService.Add(category); result.AppendLine("Added category: " + category.Id); result.AppendLine(string.Format("Have {0} row(s)", categoryService.Fetch().Count())); category.Name += " - updated"; categoryService.Update(category); result.AppendLine("Updated category: " + category.Id); categoryService.Delete(category.Id); result.AppendLine("Deleted category: " + category.Id); result.AppendLine(string.Format("Have {0} row(s)", categoryService.Fetch().Count())); result.AppendLine("test success: " + category.Id.ToString()); return(result.ToString()); } catch (Exception x) { return(x.Message); } }
public async Task <ActionResult> AddOrEdit(CategoryEditViewModel model) { try { if (!ModelState.IsValid) { return(this.Error("数据非法!")); } var record = await _categoryService.Get(model.Id); var isAdd = record == null; if (record == null) { record = PostCategoryRecord.Create(model.Id); } model.UpdateRecord(record); if (isAdd) { await _categoryService.Add(record); } return(this.Success()); } catch (ValidationException validationException) { return(this.Error(validationException.Message)); } }
public virtual async Task <ActionResult> Create(AddCategoryViewModel viewModel) { if (ModelState.IsValid) { var category = new Category { Description = viewModel.Description, ParentId = viewModel.ParentId == 0 ? null : viewModel.ParentId, KeyWords = viewModel.KeyWords, Name = viewModel.Name, DisplayOrder = viewModel.DisplayOrder, DiscountPercent = viewModel.DiscountPercent }; _attributeService.AddParentAttributeToChild(category.ParentId, category.Id); var status = _categoryService.Add(category); if (status == AddCategoryStatus.CategoryNameExist) { ModelState.AddModelError("Name", "این نام قبلا ثبت شده است"); return(View(viewModel)); } await _unitOfWork.SaveChangesAsync(); CacheManager.InvalidateChildActionsCache(); return(RedirectToAction(MVC.Admin.Category.ActionNames.Create, MVC.Admin.Category.Name)); } PopulateCategoriesDropDownList(_categoryService.GetFirstLevelCategories(), viewModel.ParentId); return(View(viewModel)); }
public ActionResult Create(Category model, HttpPostedFileBase Image) { model.IsActive = true; _categoryService.Add(model, Image); SuccessNotification("Kayıt Eklendi."); return(RedirectToAction("Index")); }
public JsonResult Create(CategoryDto category) { try { if (_categoryService.Add(category)) { var response = new DataResponeCommon() { Statu = StatuCodeEnum.OK, Message = "Thêm thành công" }; return(Json(response)); } else { var response = new DataResponeCommon() { Statu = StatuCodeEnum.InternalServerError, Message = "Thêm thất bại" }; return(Json(response)); } } catch (Exception e) { _logger.LogError(e.Message); throw; } }
public IHttpActionResult Add([FromBody] CategoryApiModel categoryApiModel) { var categoryModel = _mapper.Map <CategoryModel>(categoryApiModel); _categoryService.Add(categoryModel); return(Ok()); }
public async Task <IActionResult> Add(CategoryAddDto categoryAddDto) { if (ModelState.IsValid) { //eğer eklenecek olan veride bir hata yoksa dn ye ekliyoruz daha sonra Success olan veriyi kull. tekrardan göst. icin //Json'a donust. ve eklenen result verisinin datasını alıyoruz ve göst. olan sayfaya render ediyoruz. var result = await _categoryService.Add(categoryAddDto, "Ahmet"); if (result.ResultStatus == ResultStatus.Success) { var categoryAddAjaxModel = JsonSerializer.Serialize(new CategoryAddAjaxViewModel() { CategoryDto = result.Data, CategoryAddPartial = await this.RenderViewToStringAsync("_CategoryAddPartial", categoryAddDto) }); return(Json(categoryAddAjaxModel)); } } var categoryAddAjaxErrorModel = JsonSerializer.Serialize(new CategoryAddAjaxViewModel() { CategoryAddPartial = await this.RenderViewToStringAsync("_CategoryAddPartial", categoryAddDto), }); return(Json(categoryAddAjaxErrorModel)); }
public IActionResult Add(CategoryAddViewModel model) { if (ModelState.IsValid) { // Controlling the database exist category with same name var categoryNameControl = _categoryService.GetCategoryByName(model.Name); if (categoryNameControl != null) { TempData["Message"] = "Bu isimde bir kategori zaten kayıtlı !"; TempData["MessageState"] = "danger"; return(View(model)); } var category = new Category { Name = model.Name }; _categoryService.Add(category); TempData["Message"] = "Yeni kategori başarıyla eklendi !"; TempData["MessageState"] = "warning"; return(RedirectToAction("Categories", "Admin")); } TempData["Message"] = "Kategori ekleme işlemi başarısız oldu !"; TempData["MessageState"] = "danger"; return(View()); }
public async Task <IActionResult> Post(CategoryDto categoryDto) { ApiResponse <CategoryReadDto> response; var category = _mapper.Map <Category>(categoryDto); var resultCategory = await _categoryService.Add(category); if (resultCategory.Status == ResultStatus.Error) { response = new ApiResponse <CategoryReadDto>(null) { Title = nameof(HttpStatusCode.InternalServerError), Errors = resultCategory.Errors, Satatus = (int)HttpStatusCode.InternalServerError }; return(StatusCode(StatusCodes.Status500InternalServerError, response)); } var categoryReadDto = _mapper.Map <CategoryReadDto>(category); response = new ApiResponse <CategoryReadDto>(categoryReadDto) { Title = nameof(HttpStatusCode.OK), Satatus = (int)HttpStatusCode.OK }; return(Ok(response)); }
public IHttpActionResult Post([FromBody] Category category) { _categoryService.Add(category); var uri = new Uri(Request.RequestUri + "/" + category.Id); return(Created(uri, category)); }
public async Task <IActionResult> Add(CategoryAddDto categoryAddDto) { if (ModelState.IsValid) { var result = await _categoryService.Add(categoryAddDto, "Eray Bakır"); if (result.ResultStatus == ResultStatus.Success) { var categoryAjaxModel = JsonSerializer.Serialize(new CategoryAddAjaxViewModel { CategoryDto = result.Data, CategoryAddPartial = await this.RenderViewToStringAsync("_CategoryAddPartial", categoryAddDto) }); return(Json(categoryAjaxModel)); } } var categoryAjaxInvalidrModel = JsonSerializer.Serialize(new CategoryAddAjaxViewModel { CategoryAddPartial = await this.RenderViewToStringAsync("_CategoryAddPartial", categoryAddDto) }); return(Json(categoryAjaxInvalidrModel)); }
public virtual ActionResult Add(Category category) { if (_categoryService.IsExistByName(category.Name)) { return(PartialView(MVC.Admin.Shared.Views._Alert, new Alert { Message = "گروهی با این نام موجود می باشد", Mode = AlertMode.Error })); } if (category.Order != 0 && _categoryService.IsExistByOrder(category.Order ?? 0)) { return(PartialView(MVC.Admin.Shared.Views._Alert, new Alert { Message = "گروهی با این ترتیب موجود می باشد", Mode = AlertMode.Error })); } _categoryService.Add(category); _uow.SaveChanges(); return(PartialView(MVC.Admin.Shared.Views._Alert, new Alert { Message = "گروه جدید با موفقیت در سیستم ثبت شد", Mode = AlertMode.Success })); }
public async Task <ActionResult> Add(CategoryModel model) { var category = Mapper.Map <Category>(model); await _categoryService.Add(category).ConfigureAwait(false); return(RedirectToAction(nameof(All))); }
public IActionResult Create(CategoryViewModel categoryViewModel) { var category = new Category(); if (ModelState.IsValid) { category.Name = categoryViewModel.Name; _categoryService.Add(category); _logger.LogInformation(LoggerMessageDisplay.CategoryCreated); return(RedirectToAction(nameof(Index))); } _logger.LogError(LoggerMessageDisplay.CategoryNotCreatedModelStateInvalid); return(View(category)); }
public IActionResult AddCategory(NewCategoryViewModel model) { _categoryService.Add(new Category() { Name = model.CategoryName }); return(RedirectToAction("Categories")); }