public override CommonResponse <CategoryVM> SaveData(CategoryVM data, string transactionId)
        {
            CommonResponse <CategoryVM> response = ValidateParameter(data);

            if (response != null)
            {
                return(response);
            }

            string lastId = DbContext.Categories.Select(u => u.Id).OrderByDescending(u => u).FirstOrDefault();

            Category categoryData = new Category
            {
                Id   = CreateNewCategoryId(lastId),
                Name = data?.Name,
            };

            DbContext.Add(categoryData);

            CategoryHistory categoryDataHistory = new CategoryHistory();

            categoryDataHistory.FillFromCategory(
                categoryData,
                transactionId,
                1,
                TableTransactionOperation.Insert
                );

            DbContext.Add(categoryDataHistory);

            if (DbContext.SaveChanges() > 0)
            {
                data.Id = categoryData.Id;

                return(new CommonResponse <CategoryVM>
                {
                    Status = true,
                    Code = "S",
                    Message = "Save Data is Success!",
                    Data = new CategoryVM[] { data },
                });
            }
            else
            {
                return(new CommonResponse <CategoryVM>
                {
                    Status = false,
                    Code = "E-003",
                    Message = "Save Data Failed! Please Contact an Web Administrator!",
                    Data = new CategoryVM[] { data },
                });
            }
        }
        public override CommonResponse <CategoryVM> DeleteData(CategoryVM data, string transactionId)
        {
            IQueryable <Category> lastDataContext = DbContext.Categories.AsQueryable();

            if (string.IsNullOrEmpty(data?.Id))
            {
                return(new CommonResponse <CategoryVM>
                {
                    Status = false,
                    Code = "E-001",
                    Message = "Please fill the ID!",
                    Data = new CategoryVM[] { data },
                });
            }

            lastDataContext = lastDataContext.Where(u =>
                                                    u.Id.Equals(data.Id)
                                                    );

            Category lastData = lastDataContext.FirstOrDefault();

            if (lastData == null)
            {
                return(new CommonResponse <CategoryVM>
                {
                    Status = false,
                    Code = "E-002",
                    Message = string.Format("Data not found for ID {0}, please fill the right ID!", data?.Id),
                    Data = new CategoryVM[] { data },
                });
            }

            int historySequence = lastData?.CategoryHistories?
                                  .Select(u => u.Seq)
                                  .OrderByDescending(u => u)
                                  .FirstOrDefault() ?? 0;

            lastData.IsDeleted = true;

            CategoryHistory categoryDataHistory = new CategoryHistory();

            categoryDataHistory.FillFromCategory(
                lastData,
                transactionId,
                historySequence + 1,
                TableTransactionOperation.Delete
                );

            DbContext.Add(categoryDataHistory);

            if (DbContext.SaveChanges() > 0)
            {
                return(new CommonResponse <CategoryVM>
                {
                    Status = true,
                    Code = "S",
                    Message = "Delete Data is Success!",
                    Data = new CategoryVM[] { data },
                });
            }
            else
            {
                return(new CommonResponse <CategoryVM>
                {
                    Status = false,
                    Code = "E-003",
                    Message = "Delete Data Failed! Please Contact an Web Administrator!",
                    Data = new CategoryVM[] { data },
                });
            }
        }