// Form to edit a category public ActionResult Edit(int?id) { if (id != null) { try { ICategoryModel category = categoryData.FindById((int)id); if (category == null) { log.Error("Could't find a category in the Database - return null"); return(View("ErrorEdit")); } return(View(category)); } catch (Exception ex) { log.Error("Could't find a category in the Database", ex); return(View("ErrorRetriveData")); } } else { log.Error("The category ID was null while trying to edit"); return(View("ErrorEdit")); } }
public ActionResult Create([Bind(Include = "ID,Name")] CategoryModel category) { if (ModelState.IsValid) { try { // Checking if already exist a category with same name (case insensitive) if (categoryData.CheckIfAlreadyExist(category.Name) == false) { ICategoryModel model = category; categoryData.Create(model); return(RedirectToAction("Index")); } else { log.Info("The user tried to add a category that already existed"); return(View("AlreadyExists")); } } catch (Exception ex) { log.Error("Could't create a new category in the Database", ex); return(View("ErrorRetriveData")); } } else { log.Error("The model state of the category is invalid"); return(View("WrongData")); } }
public string GetFullPathString(ICategoryModel category, string delimeter, IDictionary <Guid, ICategoryModel> categoriesDictionary) { var path = GetFlattenPath(LinqExtensions.Enumerable(category), categoriesDictionary); var pathString = String.Join(delimeter, path.Select(c => c.Name)); return(pathString); }
public async Task <IResponseModel> AddCategoryAsync(ICategoryModel model) { try { var category = new Category { Id = Guid.NewGuid(), Name = model.Name, IsDeleted = false, UserId = model.UserId }; _db.Categories.Add(category); await _db.SaveChangesAsync(); _response.Status = true; _response.Message = "Category successfully added."; return(_response); } catch (Exception ex) { _response.Status = false; _response.Message = "Error adding category."; return(_response); } }
public async Task <ActionResult> Index(CancellationToken cancellationToken) { ViewData[Constant.FormTitle] = "ADD Category"; ICategoryModel model = await _service.IndexAsync(this.HttpContext.ApplicationInstance.Context, GetCanellationToken(cancellationToken)); return(View(model)); }
public async Task DeleteCategory(ICategoryModel category, CancellationToken token) { if (category == null) { return; } await category.Delete(token); }
public async Task SaveCategory(ICategoryModel newCategory, CancellationToken token) { if (newCategory == null) { return; } await newCategory.Save(token); }
public CategoryListViewItemViewModel(ICategoryModel model, ILocalizationService localizationService) { Model = model; _localizationService = localizationService; Title = model.Title; HexColor = model.HexColor; TypeTitle = GetTypeTitle(Model.Type); ArchiveTitle = Model.IsArchived ? _localizationService.GetTranslateByKey(Localization.InArchive) : ""; }
// PUT: api/Categories/5 public void Put([FromBody] CategoryModel area) { if (ModelState.IsValid) { if (categoryData.CheckIfAlreadyExist(area.Name) == false) { ICategoryModel model = area; categoryData.Update(model); } } }
public async Task <ActionResult> IndexEdit(string hdnCategoryId, CancellationToken cancellationToken) { if (System.Convert.ToInt64(hdnCategoryId) > 0) { ViewData[Constant.FormTitle] = "Edit Category"; ICategoryModel model = await _service.IndexAsync(this.HttpContext.ApplicationInstance.Context, hdnCategoryId, GetCanellationToken(cancellationToken)); ViewData[Constant.QuerySuccess] = HttpContext.Items[Constant.QuerySuccess]; return(View("Index", model)); } else { return(Redirect("~/CategorySearch/Index")); } }
// Asks for confirmation in order to delete a category from the database public ActionResult Delete(int?id) { if (id != null) { try { ICategoryModel category = categoryData.FindById((int)id); if (category == null) { log.Error("Could't find a category in the Database - return null"); return(View("ErrorDelete")); } // Checking if the category to delete doesn't have products on the tables or alredy sold if (soldProductData.GetByCategory((int)id).Count() > 0 || soldProductAccomplishedData.GetByCategory((int)id).Count > 0) { log.Info("The user tried to delete a category with products in opened tables"); return(View("OpenedTables")); } // Getting the number of products in category in order to display to user category.NumberOfProducts = productData.GetBySubGroup((int)id).Count(); return(View(category)); } catch (Exception ex) { log.Error("Could't find a category in the Database", ex); return(View("ErrorRetriveData")); } } else { log.Error("The category ID was null while trying to delete"); return(View("ErrorDelete")); } }
public async Task <IResponseModel> UpdateCategoryAsync(ICategoryModel model) { try { _db.Update(new Category { Name = model.Name }); await _db.SaveChangesAsync(); _response.Status = true; _response.Message = "Category successfully updated."; return(_response); } catch (Exception ex) { _response.Status = false; _response.Message = "Error updating category."; return(_response); } }
public CategoryDialogViewModel(ICategoryModel model) { Model = model; switch (Model.Type) { case CategoryType.Income: _isIncome = true; break; case CategoryType.Expense: _isExpense = true; break; } IsNew = Model.IsNew; #region Init colors _color = Model.HexColor.ToSolidColorBrush(); Colors = new List <SolidColorBrush>(Constants.Colors.Length); foreach (var color in Constants.Colors) { if (Model.HexColor.ToUpperInvariant() == color.ToUpperInvariant()) { Colors.Add(_color); } else { Colors.Add(color.ToSolidColorBrush()); } } #endregion }
public CategoryController(ICategoryModel categoryModel, ILoggerManager logger, IOptions <Sheev.Common.Models.MongoDbSetting> mongoDbSettings, IOptions <Sheev.Common.Models.ApiUrlSetting> apiSettings) { _context = new Models.ContextModel(mongoDbSettings, apiSettings, logger); _context.NLogger = logger; _categoryModel = categoryModel; }
public SoldProductModel(ICategoryModel category, ITableModel table) { Category = category; Table = table; }
public async Task <IResponseModel> UpdateCategoryAsync(ICategoryModel model) => await _categoryRepo.UpdateCategoryAsync(model);
public CategoryController(ICategoryModel categoryModel) { _cateModel = categoryModel; }
public ProductModel(ICategoryModel category) { Category = category; }
public SoldProductAccomplishedModel(ICategoryModel category) { Category = category; }
public void Save(ICategoryModel model) { var category = model.Map <Category>(); categoryRepository.Save(category); }