Example #1
0
        public IActionResult GetAllCategory()
        {
            var errors         = new List <string>();
            var categoryAccess = new CategoryAccess()
            {
                ExpenseConnection = _expenseConnection
            };

            IEnumerable <Category> categoryList = null;

            try
            {
                categoryList = categoryAccess.GetAll();

                _logger.LogInformation("User : {username} fetches all category", LoggedInUser);
            }
            catch (Exception Ex)
            {
                _logger.LogInformation("User : {username} gets expection while trying to fetch data for pageno {pageNo}", LoggedInUser);

                LogExecption(Ex, _expenseConnection);

                errors = new List <string>()
                {
                    _appConfiguration.Messages.InternalServerError
                };
            }

            return(Json(new
            {
                success = (errors.Count == 0),
                data = categoryList,
                error = errors
            }));
        }
Example #2
0
        public IActionResult FindCategoryById(int id)
        {
            var errors         = new List <string>();
            var categoryAccess = new CategoryAccess()
            {
                ExpenseConnection = _expenseConnection
            };

            var category = new Category();

            try
            {
                category = categoryAccess.GetById(id);
                _logger.LogInformation("User : {username} fetches the category id : {id}", LoggedInUser, id);
            }
            catch (Exception ex)
            {
                _logger.LogInformation("User : {username} gets expection while trying to fetch the category : {id}", LoggedInUser, id);

                LogExecption(ex, _expenseConnection);

                errors = new List <string>()
                {
                    _appConfiguration.Messages.InternalServerError
                };
            }

            return(Json(new { success = (errors.Count == 0), data = category, error = errors }));
        }
 public CategoryAccessTmp(CategoryAccess categoryAccess)
 {
     Id         = categoryAccess.Id;
     RoleId     = categoryAccess.RoleId;
     Role       = categoryAccess.Role;
     CategoryId = categoryAccess.CategoryId;
     Category   = categoryAccess.Category;
 }
Example #4
0
 private void dataGridView_Category_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
 {
     if (MessageBox.Show("Are you sure you want to delete?", "Delete confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
     {
         string id = e.Row.Cells["clmID"].Value.ToString();
         CategoryAccess.Delete(id);
     }
     else
     {
         e.Cancel = true;
     }
 }
Example #5
0
        /// <summary>
        /// Calculates packages number which correspond to the Category and shows number in item "All".
        /// </summary>
        private void CalculateByCategory()
        {
            List <CategoryModel> categories = CategoryAccess.GetCategories();
            int total = 0, count = 0;

            foreach (var category in categories)
            {
                total += _instancePackages.Count(t => t.Category == category.CategoryName);
                Category[count].Count = total;
                total = 0;
                count++;
            }
        }
Example #6
0
        public IActionResult UpdateCategory(Category category)
        {
            var errors         = new List <string>();
            var categoryAccess = new CategoryAccess()
            {
                ExpenseConnection = _expenseConnection
            };

            try
            {
                _expenseConnection.BeginTransaction();
                categoryAccess.Update(category);
                _expenseConnection.Commit();

                _logger.LogInformation("User : {username} updated category '{categoryname}'", LoggedInUser, category.Name);
            }
            catch (CustomExceptions Ex)
            {
                _logger.LogWarning("User : {username} get validation exception while updating category with name '{categoryname}' ", LoggedInUser, category.Name);

                if (_expenseConnection.InTransaction)
                {
                    _expenseConnection.RollBack();
                }

                errors = (List <string>)Ex.Data["errors"];
            }
            catch (Exception Ex)
            {
                _logger.LogWarning("User : {username} get exception while updating category with name '{categoryname}' ", LoggedInUser, category.Name);

                if (_expenseConnection.InTransaction)
                {
                    _expenseConnection.RollBack();
                }

                LogExecption(Ex, _expenseConnection);

                errors = new List <string>()
                {
                    _appConfiguration.Messages.InternalServerError
                };
            }

            return(Json(new
            {
                success = (errors.Count == 0),
                data = category,
                error = errors
            }));
        }
Example #7
0
        private void FrmMain_Load(object sender, EventArgs e)
        {
            cmbCategory.DataSource      = CategoryAccess.Read_AddEmptyRow();
            cmbCategory.DisplayMember   = "NAME";
            cmbCategory.ValueMember     = "ID";
            lsbResult.DisplayMember     = "Key";
            lsbResult.ValueMember       = "ID";
            lsbLatedViews.DisplayMember = "Key";
            lsbLatedViews.ValueMember   = "ID";
            lsbMostViews.DisplayMember  = "Key";
            lsbMostViews.ValueMember    = "ID";

            txtSearchKey.Focus();
        }
Example #8
0
        /// <summary>
        /// Calculates packages number which correspond to the Tag and shows number in each tag.
        /// </summary>
        private void CalculateByTag()
        {
            List <CategoryModel> tags = CategoryAccess.GetSubcategories();
            int total = 0, count = 0;

            foreach (var category in tags)
            {
                total            += _instancePackages.Count(t => t.TagName.Contains(category.TagName));
                tags[count].Count = total;
                total             = 0;
                count++;
            }
            Tags = new ObservableCollection <CategoryModel>(tags);
        }
Example #9
0
        private void dataGridView_Category_RowLeave(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 1 && dataGridView_Category.IsCurrentCellInEditMode)
            {
                var className = dataGridView_Category[e.ColumnIndex, e.RowIndex].EditedFormattedValue.ToString();
                if (!string.IsNullOrEmpty(className))
                {
                    Category ent = new Category();
                    ent.NAME = dataGridView_Category[e.ColumnIndex, e.RowIndex].EditedFormattedValue.ToString();
                    if (dataGridView_Category["clmID", e.RowIndex].Value != null && dataGridView_Category["clmID", e.RowIndex].Value.ToString() != "")
                    {
                        ent.ID = int.Parse(dataGridView_Category["clmID", e.RowIndex].Value.ToString());
                    }

                    int updatedId = CategoryAccess.Save(ent);
                    dataGridView_Category["clmID", e.RowIndex].Value = updatedId;
                }
            }
        }
Example #10
0
        public static List <CategoryItemViewModel> categoryQueryById(string catId)
        {
            DataTable      dtCombo = new DataTable();
            CategoryAccess _access = new CategoryAccess();

            dtCombo = _access.Category_Query("Q", catId, "");
            List <CategoryItemViewModel> result = new List <CategoryItemViewModel>();

            foreach (DataRow dtr in dtCombo.Rows)
            {
                CategoryItemViewModel item = new CategoryItemViewModel
                {
                    DATATEXTFIELD  = dtr["DATATEXTFIELD"].ToString(),
                    DATAVALUEFIELD = dtr["DATAVALUEFIELD"].ToString()
                };
                result.Add(item);
            }

            return(result);
        }
Example #11
0
        public static List <PlaceModel> getProvince()
        {
            List <PlaceModel> result   = new List <PlaceModel>();
            DataTable         dtResult = new DataTable();
            CategoryAccess    _access1 = new CategoryAccess();

            dtResult = _access1.getPlace("98", "");

            foreach (DataRow dtr in dtResult.Rows)
            {
                PlaceModel item = new PlaceModel
                {
                    Name = dtr["DATATEXTFIELD"].ToString(),
                    Code = dtr["DATAVALUEFIELD"].ToString()
                };
                result.Add(item);
            }

            return(result);
        }
Example #12
0
        public static List <CategoryValueModel> GetCategoryValue(string catId)
        {
            List <CategoryValueModel> result = new List <CategoryValueModel>();
            CategoryAccess            access = new CategoryAccess();
            DataTable dtResult = access.SP_CATEGORY_VALUE_QRY(catId);

            foreach (DataRow dtr in dtResult.Rows)
            {
                CategoryValueModel item = new CategoryValueModel
                {
                    CAT_VALUE_ID   = dtr["CAT_VALUE_ID"].ToString(),
                    CAT_CODE       = dtr["CAT_CODE"].ToString(),
                    CAT_VALUE      = dtr["CAT_VALUE"].ToString(),
                    CATEGORY_ID    = dtr["CATEGORY_ID"].ToString(),
                    SEQ            = dtr["SEQ"].ToString(),
                    DICTIONARY_ID  = dtr["DICTIONARY_ID"].ToString(),
                    MOTHER_ID      = dtr["MOTHER_ID"].ToString(),
                    MOTHER_NAME    = dtr["MOTHER_NAME"].ToString(),
                    IS_ACTIVE      = dtr["IS_ACTIVE"].ToString() == "1",
                    ORDERINDEX     = dtr["ORDERINDEX"].ToString(),
                    ISEDIT         = dtr["ISEDIT"].ToString() == "1",
                    CREATE_UID     = dtr["CREATE_UID"].ToString(),
                    UPDATE_UID     = dtr["UPDATE_UID"].ToString(),
                    SUBCODE        = dtr["SUBCODE"].ToString(),
                    IS_ACTIVE2     = dtr["IS_ACTIVE2"].ToString(),
                    DICTIONARY_ID2 = dtr["DICTIONARY_ID2"].ToString(),
                };
                if (!string.IsNullOrEmpty(dtr["CREATE_DT"].ToString()))
                {
                    item.CREATE_DT = DateTime.Parse(dtr["CREATE_DT"].ToString());
                }
                if (!string.IsNullOrEmpty(dtr["UPDATE_DT"].ToString()))
                {
                    item.UPDATE_DT = DateTime.Parse(dtr["UPDATE_DT"].ToString());
                }

                result.Add(item);
            }

            return(result);
        }
Example #13
0
        public static List <CategoryModel> getCategory()
        {
            List <CategoryModel> result   = new List <CategoryModel>();
            CategoryAccess       access   = new CategoryAccess();
            DataTable            dtResult = access.SP_CATEGORY_QRY();

            foreach (DataRow dtr in dtResult.Rows)
            {
                CategoryModel item = new CategoryModel
                {
                    CATEGORY_ID    = dtr["CATEGORY_ID"].ToString(),
                    CATEGORY_NAME  = dtr["CATEGORY_NAME"].ToString(),
                    DICTIONARY_ID  = dtr["DICTIONARY_ID"].ToString(),
                    MOTHER_CAT_ID  = dtr["MOTHER_CAT_ID"].ToString(),
                    IS_ACTIVE      = dtr["IS_ACTIVE"].ToString() == "1",
                    CREATE_UID     = dtr["CREATE_UID"].ToString(),
                    UPDATE_UID     = dtr["UPDATE_UID"].ToString(),
                    ISEDIT         = dtr["ISEDIT"].ToString() == "1",
                    CATEGORY_CODE  = dtr["CATEGORY_CODE"].ToString(),
                    MOTHER_ID      = dtr["MOTHER_ID"].ToString(),
                    ISSUBCODE      = dtr["ISSUBCODE"].ToString() == "1",
                    DESCRIPTION    = dtr["DESCRIPTION"].ToString(),
                    IS_ACTIVE2     = dtr["IS_ACTIVE2"].ToString(),
                    DESCTRIM       = dtr["DESCTRIM"].ToString(),
                    DICTIONARY_ID2 = dtr["DICTIONARY_ID2"].ToString(),
                };
                if (!string.IsNullOrEmpty(dtr["CREATE_DT"].ToString()))
                {
                    item.CREATE_DT = DateTime.Parse(dtr["CREATE_DT"].ToString());
                }
                if (!string.IsNullOrEmpty(dtr["UPDATE_DT"].ToString()))
                {
                    item.UPDATE_DT = DateTime.Parse(dtr["UPDATE_DT"].ToString());
                }

                result.Add(item);
            }

            return(result);
        }
Example #14
0
        public IActionResult DeleteCategory(int id)
        {
            var errors         = new List <string>();
            var categoryAccess = new CategoryAccess()
            {
                ExpenseConnection = _expenseConnection
            };

            try
            {
                _expenseConnection.BeginTransaction();
                categoryAccess.Delete(id);
                _expenseConnection.Commit();

                _logger.LogInformation("User : {username} deleted category id '{id}'", LoggedInUser, id);
            }
            catch (Exception Ex)
            {
                _logger.LogWarning("User : {username} get exception while deleting category with id '{id}' ", LoggedInUser, id);

                if (_expenseConnection.InTransaction)
                {
                    _expenseConnection.RollBack();
                }

                LogExecption(Ex, _expenseConnection);

                errors = new List <string>()
                {
                    _appConfiguration.Messages.InternalServerError
                };
            }

            return(Json(new
            {
                success = (errors.Count == 0),
                error = errors
            }));
        }
Example #15
0
        public static List <PlaceModel> getSubPlace(string cateId, string mPlaceCode)
        {
            List <PlaceModel> result  = new List <PlaceModel>();
            DataTable         dtCombo = new DataTable();

            string[]       values   = mPlaceCode.Split('~');
            CategoryAccess _access1 = new CategoryAccess();

            dtCombo = _access1.getPlace(cateId, values[0]);

            foreach (DataRow dtr in dtCombo.Rows)
            {
                PlaceModel item = new PlaceModel
                {
                    Name = dtr["DATATEXTFIELD"].ToString(),
                    Code = dtr["DATAVALUEFIELD"].ToString()
                };
                result.Add(item);
            }

            return(result);
        }
Example #16
0
        public void Seed(string jsonText)
        {
            IList <string> allSuperKeys = OperationKeysContainer.GetAllSuperKeys();

            JObject rolesJson = JObject.Parse(jsonText);

            var errors = schema.Validate(rolesJson);

            if (errors != null && errors.Count > 0)
            {
                throw new Exception(string.Join(@"\n\n\n", errors));
            }


            int id = 0;
            int categoryAccessId = 0;

            foreach (JProperty jProp in rolesJson.Properties())
            {
                JObject userGroupJson = (JObject)jProp.Value;

                id++;

                if (!((IDictionary <string, JToken>)userGroupJson).ContainsKey("Title"))
                {
                    throw new Exception("Can not find category title");
                }

                var  roleName = jProp.Name;
                Role role     = new Role
                {
                    Id             = id,
                    Name           = roleName,
                    NormalizedName = Normalizer.Normalize(roleName),
                    Title          = (string)userGroupJson["Title"],
                    IsSuper        = ((IDictionary <string, JToken>)userGroupJson).ContainsKey("IsSuper") &&
                                     (bool)userGroupJson["IsSuper"],
                    SortNumber = id
                };

                roles.Add(role);

                if (!userGroupJson.TryGetValue("Categories", out var categoriesAccessJsonList))
                {
                    continue;
                }

                foreach (var categoriesAccessJson in categoriesAccessJsonList)
                {
                    string name = (string)categoriesAccessJson["Category"];

                    if (!categories.ContainsKey(name))
                    {
                        throw new Exception("No such category: " + name);
                    }

                    Category category = categories[name];

                    categoryAccessId++;

                    CategoryAccess categoryAccess = new CategoryAccess
                    {
                        Id         = categoryAccessId,
                        CategoryId = category.Id,
                        RoleId     = role.Id
                    };

                    if (role.CategoryAccesses == null)
                    {
                        role.CategoryAccesses = new List <CategoryAccess>();
                    }

                    role.CategoryAccesses.Add(categoryAccess);

                    categoryAccesses.Add(categoryAccess);

                    var operationKeysJsonObject = (JObject)categoriesAccessJson["OperationKeys"];

                    foreach (var operationKeyJson in operationKeysJsonObject.Properties())
                    {
                        string keyName = operationKeyJson.Name;

                        if (!role.IsSuper && allSuperKeys.Contains(keyName))
                        {
                            throw new Exception(
                                      $"Ordinary UserGroup '{role.Name}' can not contain IsSuper key '{keyName}'");
                        }

                        if (!operationKeys.ContainsKey(keyName))
                        {
                            throw new Exception($"No such key in registered keys '{keyName}'");
                        }

                        var operationKey = operationKeys[keyName];

                        CategoryOperationAccess categoryOperationAccess = new CategoryOperationAccess
                        {
                            CategoryAccessId = categoryAccess.Id,
                            OperationKeyId   = operationKey.OperationKeyId,
                            Access           = (bool)operationKeyJson.Value
                        };

                        categoryOperationAccesses.Add(categoryOperationAccess);
                    }
                }
            }
        }
Example #17
0
 private void DlgCategory_Load(object sender, EventArgs e)
 {
     dataGridView_Category.DataSource = CategoryAccess.Read();
 }
Example #18
0
 private void FrmMain_Activated(object sender, EventArgs e)
 {
     cmbCategory.DataSource = CategoryAccess.Read_AddEmptyRow();
 }
Example #19
0
 private void DlgCategorySelector_Load(object sender, EventArgs e)
 {
     cmbCategory.DataSource    = CategoryAccess.Read_AddEmptyRow();
     cmbCategory.DisplayMember = "NAME";
     cmbCategory.ValueMember   = "ID";
 }