public StatementsBaseViewModel(AddViewModel addViewModel,
                                       CategoryManager categoryManager,
                                       EditCategoriesViewModel editCategoriesViewModel)
        {
            _addViewModel            = addViewModel;
            _categoryManager         = categoryManager;
            _editCategoriesViewModel = editCategoriesViewModel;

            _categoryManager.CategoryUpdated += (s, e) => _ = GeneratePie();
        }
Example #2
0
        public ActionResult CreateCategory()
        {
            var model = new EditCategoriesViewModel
            {
                Category = new Category(),
                Features = featureRepo.Features.ToList()
            };

            return(View("EditCategories", model));
        }
        public ActionResult Edit(int id)
        {
            var category = repository.Find(id);

            if (category == null)
            {
                return(NotFound());
            }
            var model = new EditCategoriesViewModel
            {
                Id   = category.ID,
                Name = category.Name
            };

            return(View(model));
        }
Example #4
0
        private bool SaveCategories(EditCategoriesViewModel viewModel)
        {
            var requestModel = new SaveCategoriesRequestModel
            {
                EditedCategories = viewModel.Categories.Select(a => new EditCategoryModel
                {
                    Name   = a.Name,
                    Delete = a.Delete,
                    Id     = a.Id
                })
            };
            var content = JsonConvert.SerializeObject(requestModel);
            var success = _webserviceProvider.PostDataFromWebService <bool>(Controllers.Edit.ToString(), "SaveCategories", content);

            return(success);
        }
 public ActionResult Edit(int id, EditCategoriesViewModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var category = new Categories
             {
                 Name = model.Name
             };
             repository.Update(model.Id, category);
             return(RedirectToAction("index"));
         }
         return(View(model));
     }
     catch
     {
         return(View(model));
     }
 }
Example #6
0
        public ActionResult EditCategories(
            EditCategoriesViewModel model,
            int categoryId)
        {
            model.Category = categoryRepo.Categories.Single(c => c.Id == categoryId);

            model.CategoryFeaturesIds = categoryFeatureRepo.CategoryFeatures
                                        .Where(cf => cf.CategoryId == categoryId)
                                        .Select(cf => cf.FeatureId)
                                        .ToList();

            model.CategoryFeaturesNames = model.CategoryFeaturesIds.Join(featureRepo.Features,
                                                                         p => p,
                                                                         t => t.Id,
                                                                         (p, t) => t.Name).ToList();

            model.Features = featureRepo.Features.ToList();

            return(View(model));
        }
Example #7
0
        public ActionResult EditCategories(
            EditCategoriesViewModel model,
            HttpPostedFileBase categoryImg = null)
        {
            if (categoryImg != null)
            {
                model.Category.ImageMimeType = categoryImg.ContentType;
                model.Category.ImageData     = new byte[categoryImg.ContentLength];
                categoryImg.InputStream.Read(
                    model.Category.ImageData, 0, categoryImg.ContentLength);
            }
            categoryRepo.SaveCategory(model.Category);

            // saving category features
            if (model.CategoryFeaturesIds?.Count > 0)
            {
                // clear features if this category
                var categoryFeatures = categoryFeatureRepo.CategoryFeatures
                                       .Where(cf => cf.CategoryId == model.Category.Id)
                                       .ToList();
                if (categoryFeatures.Any())
                {
                    categoryFeatureRepo.DeleteCategoryFeatures(categoryFeatures);
                }

                foreach (var featureId in model.CategoryFeaturesIds)
                {
                    var catFeature = new CategoryFeature
                    {
                        CategoryId = model.Category.Id,
                        FeatureId  = featureId
                    };
                    categoryFeatureRepo.SaveCategoryFeature(catFeature);
                }
            }

            return(RedirectToAction("IndexCategories"));
        }
Example #8
0
        public IActionResult EditCategories(EditCategoriesViewModel requestModel)
        {
            if (!string.IsNullOrEmpty(Request.Form["newCategory"]))
            {
                requestModel.Categories.Add(new EditCategoryViewModel());
                return(View(requestModel));
            }

            if (requestModel.Categories.Any(a => string.IsNullOrEmpty(a.Name)))
            {
                requestModel.ErrorMessage = "Alle Textboxen müssen ausgefüllt sein";
                return(View(requestModel));
            }

            var success   = SaveCategories(requestModel);
            var viewModel = GetAllCategories();

            if (!success)
            {
                viewModel.ErrorMessage = "Ein Fehler ist aufgetreten";
            }
            return(View(viewModel));
        }