public static CategoryView ConvertToCategoryView(this Category category)
        {
            CategoryView categoryView = new CategoryView();

            categoryView.Name = category.Name;
            categoryView.Id   = category.Id;

            return(categoryView);
        }
コード例 #2
0
 public ActionResult Edit([Bind(Include = "CategoryID,Name")] CategoryView categoryView)
 {
     if (ModelState.IsValid)
     {
         serviceCategories.UpdateCategory(categoryView.ToCategory());
         return(RedirectToAction("Index"));
     }
     return(View(categoryView));
 }
コード例 #3
0
        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));
        }
コード例 #4
0
 private Category ToCategory(CategoryView view, string pic)
 {
     return(new Category
     {
         CategoryId = view.CategoryId,
         Description = view.Description,
         ImagePath = pic,
     });
 }
コード例 #5
0
ファイル: WindowService.cs プロジェクト: domerobi/PFM
        /// <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();
        }
コード例 #6
0
        public async Task <JsonResult> AddCategory([FromBody] CategoryView model)
        {
            Catergory catergory = new Catergory {
                CategoryName = model.CategoryName
            };
            await _categoryRepository.AddRecordyAsync(catergory);

            return(Json("success"));
        }
コード例 #7
0
        /// <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);
        }
コード例 #8
0
 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);
 }
コード例 #9
0
        public ActionResult Error(int id)
        {
            CategoryView categoryView = new CategoryView(serviceCategories.GetCategory(Convert.ToInt32(id)));

            if (categoryView == null)
            {
                return(HttpNotFound());
            }
            return(View(categoryView));
        }
コード例 #10
0
        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");
        }
コード例 #11
0
 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);
 }
コード例 #12
0
        public IHttpActionResult Update([FromBody] CategoryView category)
        {
            var categoryDTO = mapper.Map <CategoryView, CategoryDTO>(category);

            categoriesService.UpdateCategory(categoryDTO);

            categoriesService.SaveChanges();

            return(Ok());
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        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"));
 }
コード例 #16
0
        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));
        }
コード例 #17
0
        public ActionResult Show()
        {
            CategoryView categoryView = new CategoryView {
                Categories = _categoryManager.GetAll()
            };

            ViewBag.Show       = "Show";
            ViewBag.ActionName = "Add";
            return(View(categoryView));
        }
コード例 #18
0
        public async Task Setup()
        {
            _category = new CategoryView {
                Name = RandomData.Name
            };

            _response = await Client.PostObject($"/libraries/{LibraryId}/categories", _category);

            _assert = CategoryAssert.FromResponse(_response).InLibrary(LibraryId);
        }
コード例 #19
0
        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));
        }
コード例 #20
0
        /// <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;
        }
コード例 #21
0
 public void UpsertCategory(CategoryView category)
 {
     if (category.Id > 0)
     {
         this.UpdateCategory(category);
     }
     else
     {
         this.AddCategory(category);
     }
 }
コード例 #22
0
        public Node GetTree()
        {
            var categories    = repo.getAllCategories();
            var categoryViews = CategoryView.getViews(categories);

            Node tree = new Node();

            constructTree(tree, categoryViews.ToArray(), null);

            return(tree);
        }
コード例 #23
0
            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");
            }
コード例 #24
0
        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);
            }
        }
コード例 #25
0
        //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));
        }
コード例 #26
0
 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);
 }
コード例 #27
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));
        }
コード例 #28
0
        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));
        }
コード例 #29
0
        public static CategoryModel ConvertToModel(CategoryView result)
        {
            var categoryModel = new CategoryModel
            {
                Name        = result.Name,
                Slug        = ConvertTextToSlug(result.ShortName),
                Description = result.Description,
                Count       = 0
            };

            return(categoryModel);
        }
コード例 #30
0
        public static CategoryView ConvertToView(CategoryModel result)
        {
            var categoryView = new CategoryView
            {
                Id          = result.Id,
                Name        = result.Name,
                ShortName   = result.Slug,
                Description = result.Description
            };

            return(categoryView);
        }
コード例 #31
0
 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);
 }