Exemple #1
0
        /// <summary>
        /// Create Category
        /// </summary>
        /// <param name="category">The category</param>
        /// <returns>boolean value</returns>
        public bool CreateCategory(ISOCategory category)
        {
            if (category.ParentId == null)
            {
                var categoryExistancy = this.category.Entities.Where(x => x.ParentId == null && (x.CategoryName == category.CategoryName || x.DisplayName == category.DisplayName)).FirstOrDefault();
                if (categoryExistancy == null)
                {
                    var newFeature = this.category.Add(category);
                    UnitOfWork.Commit();
                    return(true);
                }
            }

            if (category.ParentId != null)
            {
                var categoryExistancy = this.category.Entities.Where(x => x.ParentId == category.ParentId && (x.CategoryName == category.CategoryName || x.DisplayName == category.DisplayName)).FirstOrDefault();
                if (categoryExistancy == null)
                {
                    var newFeature = this.category.Add(category);
                    UnitOfWork.Commit();
                    return(true);
                }
            }

            return(false);
        }
Exemple #2
0
        /// <summary>
        /// Update Category
        /// </summary>
        /// <param name="category">The category</param>
        /// <returns>boolean value</returns>
        public async Task <bool> UpdateCategory(ISOCategory category)
        {
            try
            {
                bool categoryExist = false;

                var categoryList = new List <ISOCategory>(await this.category.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)
                {
                    var categoryEntity = await this.category.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;
                    this.category.Update(categoryEntity);
                    var updatedcategory = UnitOfWork.Commit();
                    return(updatedcategory == 0 ? true : false);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task <HttpResponseMessage> UpdateCategory([ModelBinder(typeof(IocCustomCreationConverter))] ISOCategory categoryEntity)
        {
            try
            {
                var result = await this.categoryService.UpdateCategory(categoryEntity);

                if (result)
                {
                    return(CreateHttpResponse <ISOCategory>(HttpStatusCode.Accepted, HttpCustomStatus.Success, null, GetLocalisedString("msgCategoryupdation")));
                }
                else
                {
                    return(CreateHttpResponse <ISOCategory>(HttpStatusCode.OK, HttpCustomStatus.Failure, null, GetLocalisedString("msgCategoryDuplicate")));
                }
            }
            catch (Exception ex)
            {
                this.logger.Error(ex.Message);
                return(CreateHttpResponse <ISOCategory>(HttpStatusCode.InternalServerError, HttpCustomStatus.Failure, null, GetLocalisedString("msgWebServiceError")));
            }
        }
 public HttpResponseMessage Create([ModelBinder(typeof(IocCustomCreationConverter))] ISOCategory categoryEntity)
 {
     {
         bool result = false;
         try
         {
             result = this.categoryService.CreateCategory(categoryEntity);
             if (result)
             {
                 return(CreateHttpResponse <ISOCategory>(HttpStatusCode.Created, HttpCustomStatus.Success, null, GetLocalisedString("msgCategoryCreation")));
             }
             else
             {
                 return(CreateHttpResponse <ISOCategory>(HttpStatusCode.OK, HttpCustomStatus.Failure, null, GetLocalisedString("msgCategoryDuplicate")));
             }
         }
         catch (Exception ex)
         {
             this.logger.Error(ex.Message);
             return(CreateHttpResponse <ISOCategory>(HttpStatusCode.ExpectationFailed, HttpCustomStatus.Failure, null, GetLocalisedString("msgWebServiceError")));
         }
     }
 }
 /// <summary>
 /// Create Category
 /// </summary>
 /// <param name="category">the category</param>
 /// <returns>boolean value</returns>
 public bool CreateCategory(ISOCategory category)
 {
     return(this.categoryDataService.CreateCategory(category));
 }
        /// <summary>
        /// Update Category
        /// </summary>
        /// <param name="category">the category</param>
        /// <returns>boolean value</returns>
        public async Task <bool> UpdateCategory(ISOCategory category)
        {
            var updationStatus = await this.categoryDataService.UpdateCategory(category);

            return(updationStatus);
        }