Exemple #1
0
        public void Inventory_Category_UpdateCategory_ShouldGetException_WithDuplicateName()
        {
            try
            {
                string otherName        = "Name" + Guid.NewGuid();
                string otherDescription = "Other description";
                CreateCategoryRequest  createCategoryRequest = new CreateCategoryRequest(otherName, otherDescription);
                ICategoryService       service       = IoC.Container.Resolve <ICategoryService>();
                CreateCategoryResponse otherCategory = service.Create(createCategoryRequest);

                UpdateCategoryRequest updateCategoryRequest = new UpdateCategoryRequest()
                {
                    Id          = otherCategory.Id,
                    Name        = this.category.Name,
                    Description = "Description of category updated"
                };

                this.UpdateCategory(updateCategoryRequest);
                Assert.IsTrue(false);
            }
            catch (ValidationException exception)
            {
                Assert.IsTrue(exception.HasExceptionKey("inventory.addOrUpdateCategory.validation.nameAlreadyExisted"));
            }
        }
Exemple #2
0
        public CreateCategoryResponse CreateCategory(CreateCategoryRequest request)
        {
            var response = new CreateCategoryResponse();

            if (request.HomeId == 0)
            {
                response.AddError(Language.Resources.Category_HomeIsMandatory);
            }
            else
            {
                var existingCategory = context.Categories.Where(category => category.HomeId == request.HomeId && category.Name == request.CategoryEntity.Name && category.ParentCategoryId == request.CategoryEntity.ParentCategoryId);
                if (existingCategory != null && existingCategory.Count() > 0)
                {
                    response.AddError(Language.Resources.Category_SameNameExists);
                }
            }

            if (response.IsSuccessful)
            {
                var category = CreateNewObject();
                category.Name             = request.CategoryEntity.Name;
                category.Description      = request.CategoryEntity.Description;
                category.ParentCategoryId = request.CategoryEntity.ParentCategoryId;
                category.HomeId           = request.HomeId;

                context.Categories.Add(category);
                context.SaveChanges();
            }

            return(response);
        }
Exemple #3
0
        public CreateCategoryResponse CreateCategory(CreateCategoryRequest request)
        {
            CreateCategoryResponse response = new CreateCategoryResponse();
            Category category = new Category();

            category.CategoryName = request.CategoryName;
            category.Description  = request.Description;
            category.Picture      = request.Picture;
            category.Products     = request.Products.ConvertToProducts();

            if (category.GetBrokenRules().Count() > 0)
            {
                response.Errors = category.GetBrokenRules().ToList();
            }
            else
            {
                try {
                    _categoryRepository.Add(category);
                    _uow.Commit();
                    response.Errors = new List <BusinessRule>();
                } catch (Exception ex)
                {
                    List <BusinessRule> errors = new List <BusinessRule>();
                    do
                    {
                        errors.Add(new BusinessRule("DAL", "DAL_ERROR: " + ex.Message));
                        ex = ex.InnerException;
                    } while (ex != null);

                    response.Errors = errors;
                }
            }

            return(response);
        }
Exemple #4
0
        public CreateCategoryResponse CreateCategory(CreateCategoryRequest request)
        {
            CreateCategoryResponse res = new CreateCategoryResponse();
            string strSP = SqlCommandStore.uspCreateCategory;

            try
            {
                using (SqlCommand cmd = new SqlCommand(strSP))
                {
                    cmd.Parameters.Add("CategoryName", SqlDbType.NVarChar, 100).Value = request.CategoryName;

                    cmd.Parameters.Add("@Return", SqlDbType.Int).Direction = ParameterDirection.ReturnValue;

                    DataSet ds = DB.ExecuteSPDataSet(cmd);
                    res.Code = (ReturnCode)Convert.ToInt32(cmd.Parameters["@Return"].Value);

                    if (res.Code != ReturnCode.Success)
                    {
                        DB.RollBackTran();
                        return(res);
                    }
                    return(res);
                }
            }
            catch (Exception ex)
            {
                LogWriter.WriteLogException(ex);
                res.Code = ReturnCode.Fail;
                return(res);
            }
        }
        public void Inventory_Category_CreateCategory_ShouldBeSuccess_WithValidRequest()
        {
            string name = "Name of Category" + Guid.NewGuid().ToString("N");
            string desc = "Desc of Category";
            CreateCategoryResponse permission = this.CreateCategoryItem(name, desc);

            Assert.IsNotNull(permission);
        }
Exemple #6
0
        private CreateCategoryResponse CreateCategoryItem(string name, string desc)
        {
            CreateCategoryRequest  request  = new CreateCategoryRequest(name, desc);
            ICategoryService       service  = IoC.Container.Resolve <ICategoryService>();
            CreateCategoryResponse category = service.Create(request);

            return(category);
        }
Exemple #7
0
        public static CreateCategoryResponse Unmarshall(UnmarshallerContext context)
        {
            CreateCategoryResponse createCategoryResponse = new CreateCategoryResponse();

            createCategoryResponse.HttpResponse = context.HttpResponse;
            createCategoryResponse.RequestId    = context.StringValue("CreateCategory.RequestId");
            createCategoryResponse.CategoryId   = context.StringValue("CreateCategory.CategoryId");

            return(createCategoryResponse);
        }
Exemple #8
0
        protected override void OnInit()
        {
            base.OnInit();
            string name = "Name" + Guid.NewGuid();
            string desc = "Desc" + Guid.NewGuid();
            CreateCategoryRequest request = new CreateCategoryRequest(name, desc);
            ICategoryService      service = IoC.Container.Resolve <ICategoryService>();

            this.category = service.Create(request);
        }
Exemple #9
0
        public CreateCategoryResponse SaveCategory(CreateCategoryRequest createCategoryRequest)
        {
            var category = messageMapper.MapToCategory(createCategoryRequest.Category);

            categoryRepository.SaveCategory(category);
            var createbrandresponse = new CreateCategoryResponse {
                Category = messageMapper.MapToCategoryDto(category)
            };

            return(createbrandresponse);
        }
        public JsonResult Create(CategoryDetailView vm)
        {
            CreateCategoryRequest request = new CreateCategoryRequest();

            request.CategoryName = vm.CategoryName;
            request.Description  = vm.Description;
            request.Picture      = vm.Picture;
            CreateCategoryResponse response = _categoryService.CreateCategory(request);

            return(Json(response));
        }
Exemple #11
0
        public void Inventory_Category_DeleteCategory_ShouldBeSuccess_WithValidRequest()
        {
            string                 name            = "Name of category";
            string                 description     = "Description of category";
            ICategoryService       categoryService = IoC.Container.Resolve <ICategoryService>();
            CreateCategoryResponse category        = this.CreateCategoryItem(name, description);

            this.DeleteCategory(category.Id);
            GetCategoryResponse deletedCategory = categoryService.GetCategory(category.Id);

            Assert.IsNull(deletedCategory);
        }
Exemple #12
0
        public IHttpActionResult AddCategory(CreateCategoryRequest request)
        {
            var response = new CreateCategoryResponse();
            var dtoInput = AutoMapper.Mapper.Map <CreateNewCategoryInput>(request);

            try
            {
                _categoryBLL.AddNewCategory(dtoInput);
            }
            catch (Exception ex)
            {
                response.Messages = ex.Message;
                response.Success  = false;
            }
            return(Ok(response));
        }
        public void Consume(IConsumeContext <CreateCategoryRequest> context)
        {
            var request  = context.Message;
            var category = _Mapper.Map <Domain.Category>(request.Category);

            _DbContext.Categories.Add(category);
            _DbContext.SaveChanges();

            var response = new CreateCategoryResponse
            {
                Category      = _Mapper.Map <Category>(category),
                CorrelationId = request.CorrelationId,
                Result        = MessageResult.Success
            };

            context.Respond(response);
        }
Exemple #14
0
        public CreateCategoryResponse CreateCategory(CreateCategoryRequest request)
        {
            CreateCategoryResponse response = new CreateCategoryResponse();

            try
            {
                Category category = request.ConvertToCategory();
                categoryRepository.Create(category);
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return(response);
        }
        public CreateCategoryResponse SaveCategory(CreateCategoryRequest request)
        {
            var response = new CreateCategoryResponse();

            WithErrorHandling(() =>
            {
                var category = request.Category.MapToCategory();
                _categoryRepository.SaveCategory(category);

                var categoryDto   = category.MapToCategoryDto();
                response.Category = categoryDto;
                response.Messages.Add("Successfully saved the category");
                response.StatusCode = HttpStatusCode.Created;
            }, response);

            return(response);
        }
Exemple #16
0
 public ActionResult Edit(CategorySinglePageViewModel model)
 {
     if (model.CategoryViewModel.CategoryId == 0)
     {
         CreateCategoryRequest  request  = new CreateCategoryRequest();
         CreateCategoryResponse response = new CreateCategoryResponse();
         request.Name = model.CategoryViewModel.Name;
         response     = categoryService.CreateCategory(request);
         if (response.Success)
         {
             return(RedirectToAction("Index"));
         }
         else
         {
             model.Success      = false;
             model.ErrorMessage = response.Message;
             return(View(model));
         }
     }
     else
     {
         UpdateCategoryRequest  request  = new UpdateCategoryRequest();
         UpdateCategoryResponse response = new UpdateCategoryResponse();
         request.CategoryId = model.CategoryViewModel.CategoryId;
         request.Name       = model.CategoryViewModel.Name;
         response           = categoryService.UpdateCategory(request);
         if (response.Success)
         {
             return(RedirectToAction("Index"));
         }
         else
         {
             model.Success      = false;
             model.ErrorMessage = response.Message;
             return(View(model));
         }
     }
 }
        public async Task UpdateCategoryCommandTestAsync(string identityUserId, int categoryId, string title, string titleImagePath, CreateCategoryResponse result)
        {
            UpdateCategoryCommand request = new UpdateCategoryCommand
            {
                CategoryId     = categoryId,
                IdentityUserId = identityUserId,
                Title          = title,
                TitleImagePath = titleImagePath,
            };
            UpdateCategoryCommandHandler handler = new UpdateCategoryCommandHandler(_updateFixture.Context);
            var expectedResult = await handler.Handle(request, new CancellationToken());

            Assert.Equal(expectedResult.IsSuccessful, result.IsSuccessful);
            if (expectedResult.IsSuccessful)
            {
                Category category = await _updateFixture.Context.Categories
                                    .Include(c => c.Creator)
                                    .Include(c => c.TitleImage)
                                    .Where(c => c.Id == expectedResult.Id)
                                    .SingleOrDefaultAsync();

                Assert.Equal(category.Title, title);
                Assert.Equal(category.TitleImage.Path, titleImagePath);
                Assert.Equal(category.Creator.IdentityUserId, identityUserId);
            }
            Assert.Equal(expectedResult.Message, result.Message);
        }