/// <summary>
        /// Creates the category.
        /// </summary>
        /// <param name="category">The category.</param>
        /// <returns>Boolean Value</returns>
        public bool CreateCategory(ISPCategory category)
        {
            if (category.ParentId == null)
            {
                var exists = partnerCategory.Entities
                             .Where(x => x.CategoryName == category.CategoryName || x.DisplayName == category.DisplayName)
                             .FirstOrDefault();
                if (exists != null)
                {
                    return(false);
                }

                var newFeature = partnerCategory.Add(category);
                UnitOfWork.Commit();
                return(true);
            }

            if (category.ParentId != null)
            {
                var categoryExistancy = partnerCategory.Entities.Where(x => x.ParentId == category.ParentId && (x.CategoryName == category.CategoryName || x.DisplayName == category.DisplayName)).FirstOrDefault();
                if (categoryExistancy == null)
                {
                    var newFeature = partnerCategory.Add(category);
                    UnitOfWork.Commit();
                    return(true);
                }
            }
            return(false);
        }
        /// <summary>
        /// Update Category
        /// </summary>
        /// <param name="category">The category.s</param>
        /// <returns>boolean Value.</returns>
        public async Task <bool> UpdateCategory(ISPCategory category)
        {
            try
            {
                bool categoryExist = false;

                var categoryList = new List <ISPCategory>(await this.partnerCategory.GetAllAsync());
                if (categoryList.Count() > 1)
                {
                    var item = categoryList.FirstOrDefault(x => x.Id == category.Id);
                    categoryList.Remove(item);
                    if (category.ParentId != null)
                    {
                        categoryExist = categoryList.Where(x => x.ParentId == category.ParentId && (x.CategoryName == category.CategoryName || x.DisplayName == category.DisplayName)).Any();
                    }

                    if (category.ParentId == null)
                    {
                        categoryExist = categoryList.Where(x => x.ParentId == null && (x.CategoryName == category.CategoryName || x.DisplayName == category.DisplayName)).Any();
                    }
                }

                if (categoryExist)
                {
                    return(false);
                }



                var categoryEntity = await partnerCategory.GetByIdAsync(category.Id);

                categoryEntity.Id                  = category.Id;
                categoryEntity.ParentId            = category.ParentId;
                categoryEntity.SortOrder           = category.SortOrder;
                categoryEntity.EditedDate          = category.EditedDate;
                categoryEntity.DisplayName         = category.DisplayName;
                categoryEntity.CreatedDate         = category.CreatedDate;
                categoryEntity.CategoryName        = category.CategoryName;
                categoryEntity.CategoryDescription = category.CategoryDescription;
                categoryEntity.IconClass           = category.IconClass;
                partnerCategory.Update(categoryEntity);
                var updatedcategory = UnitOfWork.Commit();
                return(updatedcategory == 0 ? true : false);
            }


            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task <HttpResponseMessage> UpdateCategory([ModelBinder(typeof(IocCustomCreationConverter))] ISPCategory categoryEntity)
        {
            try
            {
                var result = await categoryService.UpdateCategory(categoryEntity);

                if (!result)
                {
                    return(CreateHttpResponse <ISPCategory>(HttpStatusCode.OK, HttpCustomStatus.Failure, null, GetLocalisedString("msgCategoryDuplicate")));
                }

                return(CreateHttpResponse <ISPCategory>(HttpStatusCode.Accepted, HttpCustomStatus.Success, null, GetLocalisedString("msgCategoryupdation")));
            }
            catch (Exception ex)
            {
                this.logger.Error(ex.Message);
                return(CreateHttpResponse <ISPCategory>(HttpStatusCode.InternalServerError, HttpCustomStatus.Failure, null, GetLocalisedString("msgWebServiceError")));
            }
        }
        public HttpResponseMessage Create([ModelBinder(typeof(IocCustomCreationConverter))] ISPCategory categoryEntity)
        {
            {
                bool result = false;
                try
                {
                    result = categoryService.CreateCategory(categoryEntity);
                    if (!result)
                    {
                        return(CreateHttpResponse <ISPCategory>(HttpStatusCode.OK, HttpCustomStatus.Failure, null, GetLocalisedString("msgCategoryDuplicate")));
                    }

                    return(CreateHttpResponse <ISPCategory>(HttpStatusCode.Created, HttpCustomStatus.Success, null, GetLocalisedString("msgCategoryCreation")));
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                    return(CreateHttpResponse <ISPCategory>(HttpStatusCode.ExpectationFailed, HttpCustomStatus.Failure, null, GetLocalisedString("msgWebServiceError")));
                }
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Create Category
 /// </summary>
 /// <param name="category">The category</param>
 /// <returns>Boolean Value</returns>
 public bool CreateCategory(ISPCategory category)
 {
     return(categoryDataService.CreateCategory(category));
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Update Category
        /// </summary>
        /// <param name="category">The category</param>
        /// <returns>Boolean Value</returns>
        public async Task <bool> UpdateCategory(ISPCategory category)
        {
            var success = await categoryDataService.UpdateCategory(category);

            return(success);
        }