public static CategoryView ConvertToCategoryView(this Category category) { CategoryView categoryView = new CategoryView(); categoryView.Name = category.Name; categoryView.Id = category.Id; return(categoryView); }
public ActionResult Edit([Bind(Include = "CategoryID,Name")] CategoryView categoryView) { if (ModelState.IsValid) { serviceCategories.UpdateCategory(categoryView.ToCategory()); return(RedirectToAction("Index")); } return(View(categoryView)); }
public IActionResult create([FromBody] CategoryView newCategory) { //[FromBody]-> because the Categories attributes declaring in body in the postman var category = _mapper.Map <Categories>(newCategory); //it will map object from CategoryView into Categories _categoriesRepository.createCategories(category); return(Ok(category)); }
private Category ToCategory(CategoryView view, string pic) { return(new Category { CategoryId = view.CategoryId, Description = view.Description, ImagePath = pic, }); }
/// <summary> /// Opens a new window to create a new category or modify the selected /// </summary> /// <param name="viewModel">View model for the window</param> public void OpenCategoryWindow(CategoryViewModel viewModel) { CategoryView view = new CategoryView() { DataContext = viewModel }; view.ShowDialog(); }
public async Task <JsonResult> AddCategory([FromBody] CategoryView model) { Catergory catergory = new Catergory { CategoryName = model.CategoryName }; await _categoryRepository.AddRecordyAsync(catergory); return(Json("success")); }
/// <summary> /// Edit Category /// </summary> /// <param name="model"></param> /// <param name="message"></param> /// <returns></returns> public CategoryView Edit(CategoryView model, out string message) { CategoryView result = new CategoryView(); message = null; try { var category = entities.Categories.Find(model.ID); if (category != null) { category.Name = model.Name; category.ParentID = model.ParentID; category.Language = model.Language; category.Image = model.Image; category.ShowOnHome = model.ShowOnHome; category.CatalogueId = model.CatalogueId; if (String.IsNullOrEmpty(model.MetaTitle)) { model.MetaTitle = StringHelper.ToUnsignString(model.Name); } else { category.MetaTitle = model.MetaTitle; } category.SeoTitle = model.SeoTitle; category.MetaDescriptions = model.MetaDescriptions; category.MetaKeywords = model.MetaKeywords; category.Status = model.Status; category.ModifiedBy = model.ModifiedBy; category.ModifiedDate = DateTime.Now; if (entities.SaveChanges() > 0 && category.ID > 0) { result = GetCategoryById(category.ID); } else { message = StaticResources.Resources.MSG_THE_CATEGORY_HAS_UPDATED_UNSUCCESSFULLY; } } else { message = StaticResources.Resources.MSG_THE_CATEGORY_HAS_NOT_FOUND; } } catch (Exception ex) { string subject = "Error " + SiteSetting.SiteName + " at Edit at CategoryRepo at Model.Repository "; message = StringHelper.Parameters2ErrorString(ex, model.ID); MailHelper.SendMail(SiteSetting.EmailAdmin, subject, message); } return(result); }
public int Create(CategoryView item) { Entity.Category cate = new Entity.Category() { id = item.id, name_category = item.name_category, status = item.status }; database.Categories.Add(cate); database.SaveChanges(); return(cate.id); }
public ActionResult Error(int id) { CategoryView categoryView = new CategoryView(serviceCategories.GetCategory(Convert.ToInt32(id))); if (categoryView == null) { return(HttpNotFound()); } return(View(categoryView)); }
public void Category_CategoryView_Mapping() { //Act cv = AutoMapperHelper.Get <Category, CategoryView>(category); //Assert Assert.IsNotNull(cv); Assert.AreSame(cv.Name, category.Name, "Name property is not matching"); Assert.AreEqual(cv.Id, category.CategoryId, "Id property is not matching"); }
public CategoryAssert ShouldBeSameAs(CategoryView expected, bool matchLinks = false) { _category.Id.Should().Be(expected.Id); _category.Name.Should().Be(expected.Name); if (matchLinks) { _category.Links.Should().BeEquivalentTo(expected.Links); } return(this); }
public IHttpActionResult Update([FromBody] CategoryView category) { var categoryDTO = mapper.Map <CategoryView, CategoryDTO>(category); categoriesService.UpdateCategory(categoryDTO); categoriesService.SaveChanges(); return(Ok()); }
public async Task Setup() { _expectedCategory = new CategoryView { Id = RandomData.Number, Name = RandomData.Name }; _response = await Client.PutObject($"/libraries/{LibraryId}/categories/{_expectedCategory.Id}", _expectedCategory); _assert = CategoryAssert.FromResponse(_response).InLibrary(LibraryId); }
private void AddCategory(CategoryView category) { var categoryAdd = AutoMapper.Mapper.Map <CategoryView, Category>(category); using (var onlineShopContext = new OnlineShopWebEntities()) { onlineShopContext.Category.Add(categoryAdd); onlineShopContext.SaveChanges(); } }
public IActionResult NewCategory(CategoryView NewCategory) { if (ModelState.IsValid) { dbContext.Categories.Add(NewCategory.category); dbContext.SaveChanges(); return(RedirectToAction("CategoryView")); } return(View("CategoryView")); }
public ActionResult ShowCategory(int id) { DataLayer dal = new DataLayer(); CategoryView cav = new CategoryView(); cav.category = (dal.Categories.First(x => x.CatId == id)); cav.products = (from pro in dal.Products where pro.CatId == id select pro).ToList <Product>(); return(View(cav)); }
public ActionResult Show() { CategoryView categoryView = new CategoryView { Categories = _categoryManager.GetAll() }; ViewBag.Show = "Show"; ViewBag.ActionName = "Add"; return(View(categoryView)); }
public async Task Setup() { _category = new CategoryView { Name = RandomData.Name }; _response = await Client.PostObject($"/libraries/{LibraryId}/categories", _category); _assert = CategoryAssert.FromResponse(_response).InLibrary(LibraryId); }
public async Task <ActionResult> Edit(CategoryView view) { var category = ToCategorys(view); if (ModelState.IsValid) { using (var transaction = db.Database.BeginTransaction()) { try { var pic = string.Empty; var folder = "~/Content/Categories"; if (view.ImageFile != null) { pic = FilesHelper.UploadPhoto(view.ImageFile, folder, string.Format("{0}", category.Description), string.Format("{0}", category.CategoryId)); category.ImageMimeType = view.ImageFile.ContentType; int length = view.ImageFile.ContentLength; byte[] buffer = new byte[length]; view.ImageFile.InputStream.Read(buffer, 0, length); category.ImagenCategory = buffer; } db.Entry(category).State = EntityState.Modified; await db.SaveChangesAsync(); transaction.Commit(); return(RedirectToAction("Index")); } catch (Exception ex) { transaction.Rollback(); if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message.Contains("_Index") && ex.InnerException.InnerException.Message.Contains("REFERENCE")) { ModelState.AddModelError(string.Empty, "There are a record with the same value"); } else { ModelState.AddModelError(string.Empty, ex.Message); string message = string.Format("<b>Message:</b> {0}<br /><br />", ex.Message); message += string.Format("<b>StackTrace:</b> {0}<br /><br />", ex.StackTrace.Replace(Environment.NewLine, string.Empty)); message += string.Format("<b>Source:</b> {0}<br /><br />", ex.Source.Replace(Environment.NewLine, string.Empty)); message += string.Format("<b>TargetSite:</b> {0}", ex.TargetSite.ToString().Replace(Environment.NewLine, string.Empty)); ModelState.AddModelError(string.Empty, message); } } } } return(View(category)); }
/// <summary> /// Thread body /// </summary> /// <param name="state"></param> private void StartWork(object state) { CategoryView categoryView = state as CategoryView; category savedCategory = null; category theCategory = new category(); categoryView.Merge(theCategory, editMode); // Save to backend AutoResetEvent nextOneAutoResetEvent = new AutoResetEvent(false); EventHandler <save_CategoryCompletedEventArgs> h1 = (s, e) => { // TODO: handle error from server side savedCategory = e.Result; nextOneAutoResetEvent.Set(); }; Globals.WSClient.save_CategoryCompleted += h1; Globals.WSClient.save_CategoryAsync(theCategory); nextOneAutoResetEvent.WaitOne(); Globals.WSClient.save_CategoryCompleted -= h1; // Check return result. If failure, savedCategory will be null if (savedCategory != null) { this.Dispatcher.BeginInvoke(delegate() { categoryView.Restore(new CategoryView(savedCategory)); }); } else { // Show error message ShopproHelper.ShowMessageWindow(this, "Error", "Fail to save this entry. It is probably because you are trying to save a entry with conficting fields. \n'Name' and 'Url' fields are required unique for category.", false); // Back to readonly mode this.Dispatcher.BeginInvoke(delegate() { // Restore cached UI data categoryView.CancelEdit(); this.itemDataForm.CancelEdit(); }); } // Hide busy indicator ShopproHelper.HideBusyIndicator(this); if (this.ContentPageCtx.GotoAddNewPage) { ShopproHelper.GoToContentPage(this, PageEnum.CategoryListPage); } // No unsaved item this.editMode = DataFormMode.ReadOnly; }
public void UpsertCategory(CategoryView category) { if (category.Id > 0) { this.UpdateCategory(category); } else { this.AddCategory(category); } }
public Node GetTree() { var categories = repo.getAllCategories(); var categoryViews = CategoryView.getViews(categories); Node tree = new Node(); constructTree(tree, categoryViews.ToArray(), null); return(tree); }
public void ShouldShowCategoryWithNinetyFivePercentDiscount() { var category = new Category(Fixture.Item, Fixture.ConfigWithNinetyFiveDiscount); var categoryView = new CategoryView(category); Equal(categoryView.Show, $"名称:{category.Config.Name}, " + $"数量:{category.Item.Quantity}{category.Config.Unit}, " + $"单价:{category.Config.Price}(元), " + $"小计:{category.Subtotal}(元), " + $"节省:{category.Saved}(元)\n"); }
public static List <CategoryView> GetCategoriesNamesForSearchName(int categoryID, string productName) { List <CategoryView> listCategories = new List <CategoryView>(); if (categoryID == -1) { using (sklepEntities db = new sklepEntities()) { var tempCategories = from pr in db.Products where pr.Name.Contains(productName) join cat in db.Categories on pr.CategoryID equals cat.CategoryID select new { cat.CategoryID, cat.Name, cat.ParentCategoryID }; var categories = tempCategories.GroupBy(p => p.CategoryID).Select(s => s.FirstOrDefault()); foreach (var item in categories) { CategoryView tempCategory = new CategoryView(); tempCategory.CategoryID = item.CategoryID; tempCategory.Name = item.Name; tempCategory.ParentCategoryID = item.ParentCategoryID; listCategories.Add(tempCategory); } return(listCategories); } } else { using (sklepEntities db = new sklepEntities()) { Categories category = db.Categories.Where(x => x.CategoryID == categoryID).Single(); int parentCategoryID = category.ParentCategoryID; var categories = db.Categories.Where(x => x.ParentCategoryID == parentCategoryID && x.CategoryID != parentCategoryID); var tempCategories = from pr in db.Products where pr.Name.Contains(productName) join cat in categories on pr.CategoryID equals cat.CategoryID select new { cat.CategoryID, cat.Name, cat.ParentCategoryID }; var tempCategories1 = tempCategories.GroupBy(p => p.CategoryID).Select(s => s.FirstOrDefault()); foreach (var item in tempCategories1) { CategoryView tempCategory = new CategoryView(); tempCategory.CategoryID = item.CategoryID; tempCategory.Name = item.Name; tempCategory.ParentCategoryID = item.ParentCategoryID; listCategories.Add(tempCategory); } } return(listCategories); } }
//Category Actions public async Task <IActionResult> CategoryList() { CategoryView cv = new CategoryView { Categories = await db.Categories.ToListAsync(), Categories2 = await db.Categories2.ToListAsync(), Categories3 = await db.Categories3.ToListAsync(), }; return(View(cv)); }
public int Update(CategoryView item) { if (CheckNameExist(item.name_category, item.id) == false) { var q = database.Categories.Where(d => d.id == item.id).FirstOrDefault(); q.name_category = item.name_category; q.status = item.status; database.SaveChanges(); return(1); } return(0); }
/// <summary> /// Retrieves all Category objects based on search term matching Category.Name /// </summary> /// <returns>List of List of base class object</returns> public static List <List <object> > GetCategoriesByKeyword() { Console.Clear(); var api = new API(); Console.Write("Enter search term:"); var keyword = Console.ReadLine(); var categoryList = api.GetCategories(keyword); var categoryListData = CategoryConverters.CategoryConverter(categoryList); return(CategoryView.CategoryListReader(categoryListData)); }
public IViewComponentResult Invoke(int categoryId) { CategoryView category = eCommerce.GetCategoryBy(categoryId); var crumbs = new LinkedList <HtmlLinkAttributes>(); while (category != null) { crumbs.AddFirst(new HtmlLinkAttributes(category.Name, Url.Action("Search", "ProductType", new { categoryId = category.Id }))); category = eCommerce.GetParentCategory(int.Parse(category.Id)); } return(View(crumbs)); }
public static CategoryModel ConvertToModel(CategoryView result) { var categoryModel = new CategoryModel { Name = result.Name, Slug = ConvertTextToSlug(result.ShortName), Description = result.Description, Count = 0 }; return(categoryModel); }
public static CategoryView ConvertToView(CategoryModel result) { var categoryView = new CategoryView { Id = result.Id, Name = result.Name, ShortName = result.Slug, Description = result.Description }; return(categoryView); }
public ActionResult AddCategory(CategoryView categoryView) { if (ModelState.IsValid) { IObjectSet categories = DB.db.QueryByExample(new shop.Models.Category(categoryView.Name)); if (categories.Count == 0) { Category category = new Category(categoryView.Name); DB.db.Store(category); return RedirectToAction("Categories", "Admin"); } ModelState["Name"].Errors.Add("Category is exist"); } return View(categoryView); }