public static SummaryCategoryViewModel ConvertToIndexCategoryView(this ecom_Categories category)
        {
            SummaryCategoryViewModel categoryView = new SummaryCategoryViewModel()
            {
                Id = category.Id,
                Name = category.Name,
                SortOrder = category.SortOrder,
                Status = EnumHelper.GetDescriptionFromEnum((Define.Status)category.Status)
            };

            return categoryView;
        }
Exemple #2
0
        /// <summary>
        /// Get category by id and return category view model object to show in client side
        /// </summary>
        /// <param name="id">id of category</param>
        /// <returns>list category view model</returns>
        public CategoryViewModel getCategoryViewModel(int id)
        {
            ecom_Categories category = db.GetCategoryById(id);

            if (category != null)
            {
                return(category.ConvertToCategoryViewModel());
            }
            else
            {
                return(null);
            }
        }
Exemple #3
0
        /// <summary>
        /// Get category by id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ecom_Categories GetCategoryById(int id)
        {
            ecom_Categories category = db.GetCategoryById(id);

            if (category != null && category.Status != (int)Define.Status.Delete)
            {
                return(category);
            }
            else
            {
                return(null);
            }
        }
        public static CategoryViewModel ConvertToCategoryViewModel(this ecom_Categories category)
        {
            CategoryViewModel viewModel = new CategoryViewModel()
            {
                Id = category.Id,
                Name = category.Name,
                Description = category.Description,
                Url = category.Url,
                SortOrder = category.SortOrder,
                ParentId = category.ParentId,
                Status = category.Status
            };

            return viewModel;
        } 
Exemple #5
0
 public bool VerifyCategory(int id, int status)
 {
     try
     {
         ecom_Categories category = db.GetByID(id);
         category.Status = status;
         db.Update(category);
         db.Save();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
 /// <summary>
 /// Delete a category by change their status to delete
 /// </summary>
 /// <param name="id">id of category</param>
 /// <returns>return true if delete success and return false if delete fail</returns>
 public bool DeleteCategory(int id)
 {
     try
     {
         ecom_Categories category = db.GetByID(id);
         category.Status = (int)Define.Status.Delete;
         db.Update(category);
         db.Save();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemple #7
0
        public static ecom_Categories ConvertToCategoryModel(this CreateCategoryPostRequest viewModel)
        {
            var category = new ecom_Categories()
            {
                Id           = viewModel.Id,
                Name         = viewModel.Name,
                Description  = viewModel.Description,
                Url          = viewModel.Url,
                SortOrder    = viewModel.SortOrder,
                ParentId     = viewModel.ParentId,
                Status       = viewModel.Status != null ? (int)viewModel.Status : (int)Define.Status.Deactive,
                CreatedBy    = null,
                CreatedDate  = DateTime.Now,
                ModifiedBy   = null,
                ModifiedDate = null
            };

            return(category);
        }
Exemple #8
0
        public static DetailCategoryViewModel ConvertToDetailCategoryViewModel(ecom_Categories category, string parentName, system_Profiles createBy, system_Profiles modifiedBy)
        {
            DetailCategoryViewModel detailCategory = new DetailCategoryViewModel()
            {
                Id             = category.Id,
                Name           = category.Name,
                ParentCategory = parentName,
                Description    = category.Description,
                Url            = category.Url,
                SortOrder      = category.SortOrder,
                Status         = EnumHelper.GetDescriptionFromEnum((Define.Status)category.Status),
                CreatedBy      = createBy != null ? createBy.UserName : "",
                CreatedDate    = string.Format("{0:yyyy-MM-dd}", category.CreatedDate),
                ModifiedBy     = modifiedBy != null ? createBy.UserName : "",
                ModifiedDate   = string.Format("{0:yyyy-MM-dd}", category.ModifiedDate)
            };

            return(detailCategory);
        }
        public static ecom_Categories ConvertToCategoryModel(this CreateCategoryPostRequest viewModel)
        {
            ecom_Categories category = new ecom_Categories()
            {
                Id = viewModel.Id,
                Name = viewModel.Name,
                Description = viewModel.Description,
                Url = viewModel.Url,
                SortOrder = viewModel.SortOrder,
                ParentId = viewModel.ParentId,
                Status = viewModel.Status,
                CreatedBy = null,
                CreatedDate = DateTime.Now,
                ModifiedBy = null,
                ModifiedDate = null,
                CreateTy = viewModel.CreateBy
            };

            return category;
        }
Exemple #10
0
        /// <summary>
        /// Update a category
        /// </summary>
        /// <param name="viewModel">information of category need to update</param>
        /// <returns>if success return true or if fail return false</returns>
        public bool UpdateCategory(CategoryViewModel viewModel)
        {
            try
            {
                ecom_Categories category = db.GetByID(viewModel.Id);
                category.Name        = viewModel.Name;
                category.Description = viewModel.Description;
                category.Url         = viewModel.Url;
                category.SortOrder   = viewModel.SortOrder;
                category.Status      = (int)viewModel.Status;
                category.ParentId    = viewModel.ParentId;

                db.Save();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemple #11
0
 /// <summary>
 /// Delete a category by change their status to delete
 /// </summary>
 /// <param name="id">id of category</param>
 /// <returns>return true if delete success and return false if delete fail</returns>
 public bool DeleteCategory(int id, string deleteBy, bool isAdmin)
 {
     try
     {
         ecom_Categories category = db.GetByID(id);
         if (isAdmin == true)
         {
             category.Status = (int)Define.Status.Delete;
         }
         else
         {
             category.Status = (int)Define.Status.WaitingDelete;
         }
         category.ModifiedTy = deleteBy;
         db.Update(category);
         db.Save();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemple #12
0
        /// <summary>
        /// Get detail category after id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DetailCategoryViewModel GetDetailCategory(int id)
        {
            string          parentCategory = "";
            ecom_Categories category       = db.GetByID(id);

            if (category == null)
            {
                return(null);
            }
            else
            {
                // Get user create brand and user last time modified brand
                system_Profiles createBy    = systemProfiles.GetByID(category.CreatedBy);
                system_Profiles modifiredBy = systemProfiles.GetByID(category.CreatedBy);
                // get parent category
                if (category.ParentId != null)
                {
                    ecom_Categories parent = db.GetByID(category.ParentId);
                    parentCategory = parent != null ? parent.Name : "";
                }

                return(category.ConvertToDetailCategoryViewModel(parentCategory, createBy, modifiredBy));
            }
        }
        /// <summary>
        /// Convert Category context model to full detail category model
        /// </summary>
        /// <param name="category"></param>
        /// <param name="parentName"></param>
        /// <param name="createBy"></param>
        /// <param name="modifiredBy"></param>
        /// <returns></returns>
        /// 
        public static DetailCategoryViewModel ConvertToDetailCategoryViewModelAdminTy(this ecom_Categories category)
        {
            DetailCategoryViewModel detailCategory = new DetailCategoryViewModel()
            {
                Id = category.Id,
                Name = category.Name,
                Description = category.Description,
                Url = category.Url,
                SortOrder = category.SortOrder,
                Status = EnumHelper.GetDescriptionFromEnum((Define.Status)category.Status),
                ParentId = category.ParentId,
                CreatedBy = category.CreateTy != null ? category.CreateTy : "",
                CreatedDate = string.Format("{0:yyyy-MM-dd}", category.CreatedDate),
                ModifiedBy = category.ModifiedTy != null ? category.ModifiedTy : "",
                ModifiedDate = string.Format("{0:yyyy-MM-dd}", category.ModifiedDate)
            };

            return detailCategory;
        }