Exemplo n.º 1
0
        public JsonResult Edit(DishStore store, int?categoryId, [System.Web.Http.FromBody] EditCategory edit)
        {
            if (!categoryId.HasValue)
            {
                return(ApiModel(message: "参数不能为空[categoryId]"));
            }

            DishCategory category = DishCategoryBLL.SingleModel.GetModel(categoryId.Value);

            if (category == null || category.storeId != store.id)
            {
                return(ApiModel(message: "非法操作"));
            }

            category.title      = edit.Name;
            category.img        = edit.Icon;
            category.name_info  = edit.Description;
            category.is_show    = edit.Display ? 1 : 0;
            category.is_order   = edit.Sort;
            category.updateTime = DateTime.Now;

            bool success = DishCategoryBLL.SingleModel.Update(category, "title,img,name_info,is_show,is_order,updateTime");

            return(ApiModel(isok: success, message: success ? "编辑成功" : "编辑失败"));
        }
Exemplo n.º 2
0
 public IActionResult EditCtg([Bind(nameof(EditCategory.Id),
                                    nameof(EditCategory.Name))]
                              EditCategory model)
 {
     //model.Edit();
     ////model.Response = new ResponseModel("Insert Successfull", ResponseType.Success);
     //return RedirectToAction("Index");
     if (ModelState.IsValid)
     {
         try
         {
             model.Edit();
             model.Response = new ResponseModel("Insert Successfull", ResponseType.Success);
             return(RedirectToAction("Index"));
         }
         catch (DuplicationException message)
         {
             model.Response = new ResponseModel(message.Message, ResponseType.Failure);
         }
         catch (Exception ex)
         {
             model.Response = new ResponseModel("Insert Failed.", ResponseType.Failure);
             // error logger code
         }
     }
     return(View(model));
 }
Exemplo n.º 3
0
        public async Task <ActionResult> Create(EditCategory model)
        {
            if (ModelState.IsValid)
            {
                using (var db = DbHelper.GetDb())
                {
                    var badges = await db.Badges.Where(b => model.BadgeIds.Contains(b.Id)).ToListAsync();

                    var category = new Category()
                    {
                        Name        = model.Name,
                        Description = model.Description,
                        Badges      = badges
                    };

                    db.Categories.Add(category);

                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index", new { id = model.Id }));
                }
            }

            return(View(model));
        }
Exemplo n.º 4
0
        public IActionResult EditCtg(int id)
        {
            var model = new EditCategory();

            model.Load(id);
            return(View(model));
        }
Exemplo n.º 5
0
 static async Task EditCategory(EditCategory obj)
 {
     var                 json                = JsonConvert.SerializeObject(obj);
     var                 httpContent         = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
     HttpClient          client              = new HttpClient();
     HttpResponseMessage httpResponseMessage = await client.PostAsync("http://localhost:2794/DictionaryCategory/EditCategory", httpContent);
 }
Exemplo n.º 6
0
        public JsonResult _CategoriesForProduct(Guid id)
        {
            var categoriesForProduct = categoryService.ListCategoriesForProduct(id);

            var categories = new EditCategory().CategoryList(categoriesForProduct, id);

            return(Json(categories, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 7
0
        public ActionResult Add()
        {
            var category = new EditCategory();

            ViewBag.Title    = Localisation.Admin.PageContent.Add;
            ViewBag.Category = Localisation.Admin.PageContent.Category;
            return(View("Edit", category));
        }
Exemplo n.º 8
0
 public async Task<IActionResult> Edit(EditCategory command)
 {
     if (ModelState.IsValid)
     {
         await Mediator.Handle(command);
         return RedirectToAction(nameof(CategoryList));
     }
     return View(command);           
 }
Exemplo n.º 9
0
        public JsonResult _CategoriesForSelectDialog(Guid id)
        {
            var categoriesForProduct   = categoryService.ListCategoriesForProduct(id);
            var allCategories          = categoryService.List();
            var allCategoriesForDialog = new EditCategory().CategoryList(allCategories, id,
                                                                         categoriesForProduct);

            return(Json(allCategoriesForDialog, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Edit(EditCategory model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var category = db.Categories.Where(c => c.CategoryId == model.CategoryId).FirstOrDefault();
                    if (category != null)
                    {
                        if (model.ParrentId == 0)
                        {
                            // Change category to top first category
                            category.CategoryName = model.CategoryName;
                            category.Description  = model.Description;
                            category.ParrentId    = null;
                            db.SaveChanges();
                            return(RedirectToAction("Index"));
                        }
                        else
                        {
                            // Get parrent category
                            var parrent = db.Categories.Where(c => c.CategoryId == model.ParrentId).FirstOrDefault();
                            if (parrent != null)
                            {
                                category.CategoryName = model.CategoryName;
                                category.Description  = model.Description;
                                category.ParrentId    = model.ParrentId;
                                db.SaveChanges();
                                return(RedirectToAction("Index"));
                            }
                            else
                            {
                                ModelState.AddModelError("", "Cập nhật loại hàng thất bại! Không tìm thấy loại hàng gốc (cha).");
                            }
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Cập nhật loại thất bại! Không tìm thấy loại hàng cần chỉnh sửa.");
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);

                // Write error log
                var log = new Log();
                log.LogDate = DateTime.Now;
                log.Action  = "Category - Edit()";
                log.Tags    = "Error";
                log.Message = ex.ToString();
                db.Logs.Add(log);
            }
            return(View(model));
        }
Exemplo n.º 11
0
 public void EditFormsCategoryApplication()
 {
     EditCategory.ClickOn();
     CategoryName.Clear();
     SaveCategory.ClickOn();
     softAssert.VerifyElementPresentInsideWindow(NameValidation, Pages.Home_Page.PopupCloseClass);
     CategoryName.SendKeys(Constant.Edit + RandomNumber.smallNumber());
     SaveCategory.ClickOn();
     softAssert.VerifySuccessMsg();
 }
        public ActionResult Edit(int id)
        {
            var model = new EditCategory();

            try
            {
                var category = db.Categories.Where(c => c.CategoryId == id).FirstOrDefault();
                if (category != null)
                {
                    model.CategoryId   = category.CategoryId;
                    model.CategoryName = category.CategoryName;
                    model.Description  = category.Description;
                    model.ParrentId    = category.ParrentId;

                    // Get category tree
                    IList <CategoryNode> nodes = new List <CategoryNode>();
                    CategoryHierarchy.AppendChildCategories(ref nodes, null);

                    // Generate select list items
                    model.SelectCategoryItems = nodes.Where(c => c.CategoryId != model.CategoryId).Select(x => new SelectListItem
                    {
                        Text     = StringExtensions.Repeat("\xA0", x.Level * 4) + x.CategoryName,
                        Value    = x.CategoryId.ToString(),
                        Selected = (x.CategoryId == model.ParrentId)
                    }).ToList();

                    // Add top root category
                    model.SelectCategoryItems.Insert(0, new SelectListItem
                    {
                        Text     = "-- Chọn loại hàng cha--",
                        Value    = "0",
                        Selected = (category.ParrentId == null)
                    });

                    return(View(model));
                }
                else
                {
                    ModelState.AddModelError("", "Không tìm thấy danh mục chỉnh sửa.");
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);

                // Write error log
                var log = new Log();
                log.LogDate = DateTime.Now;
                log.Action  = "Category - Edit()";
                log.Tags    = "Error";
                log.Message = ex.ToString();
                db.Logs.Add(log);
            }
            return(View(model));
        }
Exemplo n.º 13
0
        private void PictureBox13_Click(object sender, EventArgs e)
        {
            if (listBox6.SelectedItem != null)
            {
                int i = listBox6.SelectedIndex;

                EditCategory p = new EditCategory(levelCategory[i]);
                p.FormClosing += new FormClosingEventHandler(updAdminCategoryActions);
                p.Show();
            }
        }
Exemplo n.º 14
0
        public void ToEntity_should_map_properties()
        {
            var category = new EditCategory {
                Description = "Category 2 Description", Name = "Category 2 Name"
            };

            var categoryEntity = category.ToEntity();

            Assert.That(categoryEntity.Name, Is.EqualTo(category.Name));
            Assert.That(categoryEntity.Description, Is.EqualTo(category.Description));
        }
Exemplo n.º 15
0
        public async Task <IHttpActionResult> Put(EditCategory item)
        {
            if (ModelState.IsValid)
            {
                CategoryDto category = await _categoryService.Update(_mapper.Map <EditCategory, CategoryDto>(item));

                return(Ok(category));
            }

            return(BadRequest(ModelState));
        }
Exemplo n.º 16
0
 static void EditCommand_Execute(object param)
 {
     if (param is Category category)
     {
         var dialog = new EditCategory()
         {
             DataContext = category
         };
         dialog.ShowDialog();
     }
 }
Exemplo n.º 17
0
        private async void UIElement_OnDoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
        {
            ICategory activeCategory = (ICategory)((FrameworkElement)e.OriginalSource).DataContext;
            var       editAccount    = new EditCategory(activeCategory);
            var       result         = await editAccount.ShowAsync();

            if (result == ContentDialogResult.Primary)
            {
                ViewModel.RefreshCategoryList();
            }
        }
Exemplo n.º 18
0
        private async void AppBarButton_Click(object sender, RoutedEventArgs e)
        {
            var addAccount = new EditCategory(null, ViewModel.Category);

            var result = await addAccount.ShowAsync();

            if (result == ContentDialogResult.Primary)
            {
                ViewModel.RefreshCategoryList();
            }
        }
        public async Task <Unit> Handle(EditCategory message, CancellationToken cancellationToken)
        {
            var categoryToEdit = await this.context.Categories.FindAsync(message.Id);

            mapper.Map(message, categoryToEdit);
            categoryToEdit.UserCodeLastChange = UserCode();
            categoryToEdit.LastChangeDate     = DateTime.Now;

            await context.SaveChangesAsync();

            return(Unit.Value);
        }
Exemplo n.º 20
0
        public IActionResult Edit(int id)
        {
            var category     = categoryRepository.Get(id);
            var editcategory = new EditCategory()
            {
                ImagePath    = category.Logo,
                CategoryName = category.CategoryName,
                CategoryId   = category.CategoryId,
            };

            return(View(editcategory));
        }
Exemplo n.º 21
0
        public void FromEntity_should_map_properties()
        {
            var categoryEntity = new Category {
                Name = "Category 1", Description = "Category 1 Description"
            };
            var category = new EditCategory();

            category.FromEntity(categoryEntity);

            Assert.That(category.Name, Is.EqualTo(categoryEntity.Name));
            Assert.That(category.Description, Is.EqualTo(categoryEntity.Description));
        }
Exemplo n.º 22
0
 public void Edit(EditCategory editCategory)
 {
     try
     {
         var category = _ArcRep.GetArticleCategoryBy(editCategory.id);
         category.Edit(editCategory.Title);
         _ArcRep.Save();
     }
     catch (Exception)
     {
         throw new AccessViolationException();
     }
 }
Exemplo n.º 23
0
        public async Task OnGetAsync(int id, int pageNumber = 1)
        {
            var category = await _categoriesQueries.GetById(id);

            Category = new EditCategory
            {
                Id       = category.Id,
                Category = category.Name
            };

            Products = await LoadProductsAsync(id, pageNumber);

            Category.PageNumber = Products.Pagination.PageNumber;
        }
Exemplo n.º 24
0
        public async Task <ActionResult> Edit(EditCategory model)
        {
            if (ModelState.IsValid)
            {
                if (model.Id.HasValue)
                {
                    using (var db = DbHelper.GetDb())
                    {
                        var badges   = db.Badges.Where(b => model.BadgeIds.Contains(b.Id));
                        var category = new Category();

                        if (model.Id.HasValue)
                        {
                            category = await db.Categories.FirstOrDefaultAsync(c => c.Id == model.Id);
                        }

                        if (category.ImageId == null)
                        {
                            category.Image = new Image();
                        }


                        var matches = Regex.Match(model.ImageSource ?? "", @"data:image/(?<type>.+?),(?<data>.+)");
                        var type    = matches.Groups["type"]?.Value ?? "";
                        var data    = matches.Groups["data"]?.Value ?? "";

                        category.Image.ImageData = Convert.FromBase64String(data);
                        category.Image.Type      = type;

                        category.Badges.Clear();
                        foreach (var badge in badges)
                        {
                            category.Badges.Add(badge);
                        }

                        category.Name        = model.Name;
                        category.Description = model.Description;

                        await db.SaveChangesAsync();

                        return(RedirectToAction("Index", new { id = model.Id }));
                    }
                }

                ModelState.AddModelError("", "Id does not have value");
            }

            return(View(model));
        }
Exemplo n.º 25
0
 public IActionResult Edit(EditCategory model)
 {
     if (ModelState.IsValid)
     {
         if (categoryRepository.UpdateCategory(model) > 0)
         {
             return(RedirectToAction(actionName: "Index", controllerName: "Category"));
         }
         else
         {
             ModelState.AddModelError("", "Tên này đã tồn tại, vui lòng chọn tên khác");
         }
     }
     return(View());
 }
Exemplo n.º 26
0
        public ViewResult Edit(Guid id)
        {
            var categoryEntity = categoryService.GetSingle(id) ?? new Category();

            if (categoryEntity.Id == Guid.Empty)
            {
                ModelState.AddModelError("", Localisation.ViewModels.EditCategory.CategoryNotFound);
            }

            var category = new EditCategory();

            category.FromEntity(categoryEntity);
            ViewBag.Title    = Localisation.Admin.PageContent.Edit;
            ViewBag.Category = Localisation.Admin.PageContent.Category;
            return(View(category));
        }
Exemplo n.º 27
0
 public ActionResult UpdateCategory(int id, EditCategory editCategory)
 {
     try
     {
         Category category = repository.GetById(id);
         if (category == null)
         {
             return(NotFound());
         }
         Category c = mapper.Map(editCategory, category);
         repository.Update(c);
         return(Ok());
     }
     catch (Exception)
     {
         return(BadRequest());
     }
 }
Exemplo n.º 28
0
 void repCategories_ItemDataBound(object sender, RepeaterItemEventArgs e)
 {
     if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
     {
         if (e.Item.ItemIndex == EditIndex)
         {
             //PlaceHolder p = e.Item.FindControl("updatePlaceHodler") as PlaceHolder;
             //p.Visible = true;
             EditCategory inSideEditCategory = e.Item.FindControl("inSideEditCategory") as EditCategory;
             inSideEditCategory.Visible = true;
             //inSideEditCategory.Submit_Click += new SubmitHandler(Submit_Click);
             inSideEditCategory.CategoryID = (e.Item.DataItem as Category).CategoryID;
             inSideEditCategory.PopulateControls();
             //EditCategory editCata = new EditCategory();
             //editCata.ID = "editCata";
             //p.Controls.Add(editCata);
         }
     }
 }
        public async Task Put()
        {
            var queryHandler = new CategoryHandler(BasicNeeds);

            var categ = context.Categories.First();
            var query = new EditCategory()
            {
                Code        = "Code 3",
                Description = "Desc Code 3",
                ForEntity   = "Test ent 3",
                Id          = categ.Id,
                ParentId    = null
            };

            await queryHandler.Handle(query, CancellationToken.None);

            var cat = await context.Categories.FirstAsync <CategoryDb>(p => p.Code == "Code 3");

            Assert.IsNotNull(cat);
        }
Exemplo n.º 30
0
        static void AddCommand_Execute(object param)
        {
            EditCategory dialog;

            if (param is Category category)
            {
                dialog = new EditCategory()
                {
                    DataContext = category
                };
            }
            else
            {
                dialog = new EditCategory()
                {
                    DataContext = new Category()
                };
            }
            dialog.ShowDialog();
        }