public ActionResult Add(CategoryViewModel categoryViewModel) { string message = ""; if (ModelState.IsValid) { Category category = Mapper.Map <Category>(categoryViewModel); string errMsg = _categoryManager.UniqueTest(category); if (errMsg == "") { if (_categoryManager.Add(category)) { message = "Saved"; } else { message = "not saved"; } } else { message = errMsg; } } else { message = "modelstate is invalid"; } ViewBag.Message = message; categoryViewModel.Categories = _categoryManager.GetAll(); return(View(categoryViewModel)); }
public ActionResult SaveCategory(Category category) { if (Request.IsAuthenticated) { if (ModelState.IsValid) { category.ActionDate = DateTime.Now.ToString(); category.ActionType = ActionType.Insert; category.ActionBy = ActionType.User; ViewBag.Response = categoryManager.Add(category); } else { ViewBag.Response = 3; } ModelState.Clear(); return(View()); } else { return(HttpNotFound()); } }
private void SaveButton_Click(object sender, EventArgs e) { Model.Category category = new Model.Category(); category.Name = nameTextBox.Text; string QueryDuplicate = @"SELECT COUNT(*) FROM Categories where Name='" + category.Name + "' "; SqlCommand commandDuplicateCheck = new SqlCommand(QueryDuplicate, _con); DataTable ds = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(commandDuplicateCheck); da.Fill(ds); if (ds.Rows[0][0].ToString() == "1") { string msg = "Duplicate Entry not Allowed."; MessageBox.Show(msg); } else { bool isAdded = _CategoryManager.Add(category: category); if (isAdded) { MessageBox.Show("Successfuly Saved."); nameTextBox.Clear(); CategoryLode(); return; } MessageBox.Show("Sorry! failed."); } }
public ResponseModel <Category> Add([FromBody] Miktobutik.Models.InputModels.InputCategory category) { var result = new ResponseModel <Category>(); try { if (ModelState.IsValid) { Category NewCat = new Category() { Name = category.Name, ActiveState = category.ActiveState, Description = category.Description, Keywords = category.Keywords }; result = _categoryManager.Add(NewCat); } else { result.Success = false; result.result = null; } } catch (Exception ex) { logger.LogError(ex, ex.Message); result.Success = false; result.Message = ex.Message; } return(result); }
private void SaveButton_Click(object sender, EventArgs e) { try { if (nameTextBox.Text == "") { nameLlabel.Text = "Enter a category"; nameLlabel.ForeColor = Color.Red; return; } _category.Name = nameTextBox.Text.Trim(); bool isExist = _categoryManager.IsDuplicateData(_category); if (isExist) { nameLlabel.Text = $"Catagory {nameTextBox.Text} already in system"; nameLlabel.ForeColor = Color.Red; nameTextBox.Clear(); return; } bool isAdded = _categoryManager.Add(_category); if (isAdded) { nameLlabel.Text = $"Save category: {nameTextBox.Text} successfully"; GetData(); nameTextBox.Clear(); } } catch (Exception exception) { MessageBox.Show(exception.Message); } }
public ActionResult Add(CategoryView categoryView) { string message = null; ViewBag.ActionName = "Add"; ViewBag.ButtonName = "Save"; ViewBag.Head = "Add"; Category category = Mapper.Map <Category>(categoryView); if (categoryView.Id != 0) { ViewBag.ActionName = "Show"; if (_categoryManager.Update(category)) { message = "Category is updated successfully"; } } else { message = _categoryManager.Add(category) ? "Category is saved successfully" : "Category is not saved"; } ViewBag.Message = message; ViewBag.Save = "save"; ModelState.Clear(); return(View(new CategoryView())); }
public ActionResult Add(CategoryViewModel categoryViewModel) { string message = "<h3>Category info</h3>"; if (ModelState.IsValid) { Category category = Mapper.Map <Category>(categoryViewModel); if (_categoryManager.Add(category)) { message = "Saved"; } else { message = "Not Saved"; } } else { message = "ModelState Failed"; } ViewBag.Message = message; categoryViewModel.Categories = _categoryManager.GetAll(); return(View(categoryViewModel)); }
public ActionResult CategorySave(CategoryViewModel categoryViewModel) { string message = ""; Category category = new Category(); category.Code = categoryViewModel.Code; category.Name = categoryViewModel.Name; if (ModelState.IsValid) { if (_categoryManager.Add(category)) { message = "Category Save successfully"; } else { message = "Category Not Save !!"; } } else { message = "Failed to Submit"; } ViewBag.Message = message; return(View(categoryViewModel)); }
private void SaveButton_Click(object sender, EventArgs e) { try { _category.Name = nameTextBox.Text; if (_category.Name == String.Empty || _category.Name.Length < 2) { errorProvider.SetError(nameTextBox, "Please provide a valid category!"); } bool isAdded = _manager.Add(_category); if (isAdded) { Reset(this.Controls); _dataTable = _manager.GetCategories(); for (int i = 0; i < _dataTable.Rows.Count; i++) { categoryDataGridView.Rows.Add(_dataTable.Rows[i].Field <int>("Id"), _dataTable.Rows[i].Field <string>("Name")); } } else { MessageBox.Show("Error Occured While Saving!"); } } catch (Exception exception) { MessageBox.Show(exception.Message); } }
public ActionResult Create(Category obj) { try { if (ModelState.IsValid) { HttpPostedFileBase file = Request.Files["imageBrowes"]; var isAdded = _manager.Add(obj, file); if (isAdded) { ViewBag.Meg = "Sucessful"; //return RedirectToAction("Index"); return(RedirectToAction("Index")); } else { ViewBag.Meg = "Failed"; } } } catch (RetryLimitExceededException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log. ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(View(obj)); }
public void category_add_test() { Mock <ICategoryDal> mock = new Mock <ICategoryDal>(); CategoryManager categoryManager = new CategoryManager(mock.Object); categoryManager.Add(new Category()); }
public ActionResult Add([Bind(Include = "Id, Name, Code, IsDeleted")] CategoryViewModel categoryVm) { if (ModelState.IsValid) { Category category = new Category(); category.Id = categoryVm.Id; category.Name = categoryVm.Name; category.Code = categoryVm.Code; if (_categoryManager.Add(category)) { ViewBag.SuccessMsg = "Category Saved Successfully."; return(RedirectToAction("Index")); } else { ViewBag.FailMsg = "Vailed!"; } } else { ViewBag.FailMsg = "Validation Error!"; } return(View()); }
private void addButton_Click(object sender, EventArgs e) { errorProvider.Clear(); category.Code = codeTextBox.Text; category.CategoryName = nameTextBox.Text; if ((codeTextBox.Text.Equals("") || codeTextBox.Text.Length != 4)) { er++; errorProvider.SetError(codeTextBox, "Enter your Id and Id Must be 4 charecter"); return; } if ((nameTextBox.Text.Equals(""))) { er++; errorProvider.SetError(nameTextBox, "insert name"); return; } if (addButton.Text == "Add") { if (_categoryManager.IsNameExist(category)) { er++; errorProvider.SetError(codeTextBox, "Please Inser Unique Code"); return; } if (_categoryManager.Add(category)) { MessageBox.Show("added"); addDataGridView.DataSource = _categoryManager.Display(); codeTextBox.Clear(); nameTextBox.Clear(); } } else { if (_categoryManager.IsCodeExist(category)) { er++; errorProvider.SetError(codeTextBox, "Please Inser Unique Code"); return; } category.Id = Convert.ToInt32(idTextBox.Text); if (_categoryManager.Update(category)) { MessageBox.Show("Update"); addDataGridView.DataSource = _categoryManager.Display(); codeTextBox.Clear(); nameTextBox.Clear(); } } }
public void AddTest() { var result = _manager.Add(new Category { Name = "daily" }).Result; Assert.True(result); }
private void saveButton_Click(object sender, EventArgs e) { Category category = new Category(); //Set as Mandatory if (String.IsNullOrEmpty(codeTextBox.Text)) { MessageBox.Show("Code Can not be Empty!!!"); return; } if (String.IsNullOrEmpty(nameTextBox.Text)) { MessageBox.Show("Name Can not be Empty!!!"); return; } //Length check if (codeTextBox.Text.Length != 4) { MessageBox.Show("Code must be 4 digit!!!"); return; } category.Code = codeTextBox.Text; category.Name = nameTextBox.Text; //Check UNIQUE if (_categoryManager.IsCodeExists(category)) { MessageBox.Show(codeTextBox.Text + " Already Exists!"); return; } if (_categoryManager.IsNameExists(category)) { MessageBox.Show(nameTextBox.Text + " Already Exists!"); return; } bool isAdded = _categoryManager.Add(category); if (isAdded) { MessageBox.Show("Saved"); } else { MessageBox.Show("Not Saved"); } ShowDataGridView.DataSource = _categoryManager.Display(); }
public async Task <IActionResult> Create([Bind("Id,CategoryName")] Category category) { if (ModelState.IsValid) { await _categoryManager.Add(category).ConfigureAwait(true); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public ActionResult Add(Category category) { if (ModelState.IsValid) { _categoryManager.Add(category); } aCategory.Categories = _categoryManager.GetAll(); return(View(aCategory)); }
static void Main(string[] args) { CategoryManager _categoryManager = new CategoryManager(); Model.Model.Category category = new Model.Model.Category() { Code = "0003", Name = "Laptop" }; //Add if (_categoryManager.Add(category)) { Console.WriteLine("Saved"); } else { Console.WriteLine("Not Saved"); } //Delete if (_categoryManager.Delete(1)) { Console.WriteLine("Deleted"); } else { Console.WriteLine("Not Deleted"); } //Update category.Id = 1; category.Code = "0001"; category.Name = "Desktop"; if (_categoryManager.Update(category)) { Console.WriteLine("Updated"); } else { Console.WriteLine("Not Updated"); } //var Categories = _categoryManager.ShowAll(); //var Category = _categoryManager.Search(2); //foreach(var cate in Categories) //{ // Console.WriteLine("Code: " + cate.Code + " Name: " + cate.Name); //} //Console.WriteLine("Code: " + Category.Code + " Name: " + Category.Name); //Console.ReadKey(); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); CategoryManager manager = new CategoryManager(); manager.Add(new Entities.Category { Name = "Taze", Description = "Pideeğ" }); }
public ActionResult Create(Category category) { JsonResult jason = new JsonResult(); if (ModelState.IsValid) { jason.Data = _categoryManager.Add(category) ? new { Success = true, Message = "Saved Successfully" } : new { Success = false, Message = "Unable to Save" }; } return(jason); }
public ActionResult CreateCategory(CreateCategoryViewModel model) { var householdId = User.Identity.GetHouseholdId(); if (ModelState.IsValid && householdId != null) { _categoryManager.Add(new Category { HouseholdId = householdId.Value, Name = model.Name }); } return(RedirectToAction(nameof(Index))); }
static void Main(string[] args) { CategoryManager _categoryManager = new CategoryManager(); Category category = new Category() { Code = "0001", Name = "Arafat", }; //Add if (_categoryManager.Add(category)) { Console.WriteLine("Saved"); } else { Console.WriteLine("Not Saved"); } //Delete if (_categoryManager.Delete(1)) { Console.WriteLine("Deleted"); } else { Console.WriteLine("Not Deleted"); } //Update category.Id = 1; category.Code = "0002"; category.Name = "Mobile"; if (_categoryManager.Update(category)) { Console.WriteLine("Updated"); } else { Console.WriteLine("Not Updated"); } var categories = _categoryManager.GetAll(); var acategory = _categoryManager.GetById(1); Console.ReadKey(); }
public void Add(string contextItemPath, string name, bool expectCategory) { var settings = MockSettings(ID.NewID, ID.NewID); var templateManager = TemplateFactory.CreateTemplateManager(settings.CategoryTemplateIds.Concat(settings.BlogTemplateIds).ToArray()); var manager = new CategoryManager(settings, templateManager); using (var db = new Db { new DbTemplate("category1", settings.CategoryTemplateIds.ElementAt(0)) { new DbField("Title") }, new DbTemplate("category2", settings.CategoryTemplateIds.ElementAt(1)) { new DbField("Title") }, new DbItem("blog", ID.NewID, settings.BlogTemplateIds.First()) { new DbItem("Categories", ID.NewID, ID.NewID) { new DbItem("alpha", ID.NewID, settings.CategoryTemplateIds.ElementAt(0)), new DbItem("beta", ID.NewID, settings.CategoryTemplateIds.ElementAt(1)), new DbItem("gamma", ID.NewID, settings.CategoryTemplateIds.ElementAt(0)) }, new DbItem("Entries", ID.NewID, ID.NewID) { new DbItem("entry1", ID.NewID, settings.EntryTemplateIds.First()) } } }) { var entryItem = contextItemPath != null?db.GetItem(contextItemPath) : null; CategoryItem categoryItem = null; using (new SecurityDisabler()) { categoryItem = manager.Add(name, entryItem); } if (expectCategory) { Assert.That(categoryItem, Is.Not.Null); Assert.That(categoryItem.Name, Is.EqualTo(name)); } else { Assert.That(categoryItem, Is.Null); } } }
public void NoDuplicates() { CategoryManager.Clear(); string name1 = "Name1"; string name2 = "Name2"; string duplicate1 = "Name1"; CategoryManager.Add(name1); CategoryManager.Add(name2); CategoryManager.Add(duplicate1); Assert.AreEqual(2, CategoryManager.Categories.Count); }
public ActionResult Create([Bind(Include = "CategoryID,GeneralCategoryID,CategoryName,CategoryCode,CategoryDescription")] Category category) { if (ModelState.IsValid) { _categoryManager.Add(category); return(RedirectToAction("Index")); } var generalCategoryList = _generalCategoryManager.GetAll(); ViewBag.GeneralCategoryID = new SelectList(generalCategoryList, "GeneralCategoryID", "GeneralCategoryName"); return(View(category)); }
public void Add_WhenAddedNewCategory_ShouldAddAndReturnId() { // Arrange var categoryForAddDto = new CategoryForAddDto(); var mockCategoryDal = new MockCategoryDal().MockAdd(new Category()); var sut = new CategoryManager(mockCategoryDal.Object); // Act var result = sut.Add(categoryForAddDto); // Assert Assert.Equal(new short(), result.Data); }
public async Task <ActionResult <Category> > Post([FromBody] Category category) { try { await _categoryManager.Add(category); return(Ok(category)); } catch (Exception exception) { _logger.LogError($"Error occured during creating category. Exception: {exception.Message}"); return(BadRequest()); } }
public void Add_CategoryAdd_ReturnTrueResult() { ICategoryService categoryService = new CategoryManager(_mockCategoryDal.Object); Category category = new Category { Id = 4, Name = "Category4", CreateDate = DateTime.Now, Active = true }; var result = categoryService.Add(category); Assert.IsTrue(result.Success); }
static void Main(string[] args) { var categoryManager = new CategoryManager(new EfCategoryDal()); var category = new Category { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, Description = "Bu bir kategori", Name = "Telefon" }; categoryManager.Add(category); }
public async Task <IActionResult> Create(CategoryViewModel categoryViewModel) { try { await _categoryManager.Add(_mapper.Map <CategoryViewModel, Category>(categoryViewModel)); return(RedirectToAction(nameof(Index))); } catch (Exception exception) { _logger.LogError($"Error occured during creating category. Exception: {exception.Message}"); return(View(categoryViewModel)); } }