예제 #1
0
        public Task <DataResult <DTOCategory> > EditCategoryAsync(DTOCategory categoryDTO)
        {
            return(Task.Run(() =>
            {
                var categoryEntity = _mapper.Map <Category>(categoryDTO);
                var updatedCategoryDTO = new DTOCategory();

                if ((categoryRepository.ExistByCondition(x => (x.Name == categoryEntity.Name && x.Id == categoryEntity.Id))) || (!categoryRepository.ExistByCondition(x => x.Name == categoryEntity.Name)))
                {
                    var updatedCategoryEntity = categoryRepository.Update(categoryEntity);
                    _unitOfWork.SaveChanges();

                    updatedCategoryDTO = _mapper.Map <DTOCategory>(updatedCategoryEntity);

                    return new DataResult <DTOCategory> {
                        Errors = new List <ErrorDescriber>(), Target = updatedCategoryDTO
                    };
                }
                else
                {
                    return new DataResult <DTOCategory> {
                        Errors = new List <ErrorDescriber> {
                            new ErrorDescriber("Existed Category Name")
                        }, Target = updatedCategoryDTO
                    };
                }
            }));
        }
예제 #2
0
 /// <summary>
 /// Mapps the DTO to the entity.
 /// </summary>
 /// <param name="category"> The category entity</param>
 /// <param name="categoryDTO"> The DTO </param>
 /// <param name="unitOfWork"> Repositories Access</param>
 public void MapDTO(Category category, DTOCategory categoryDTO, UnitOfWork unitOfWork)
 {
     category.Id   = categoryDTO.Id;
     category.Name = categoryDTO.Name;
     FillBooks(category, categoryDTO.IdEditorial, categoryDTO.Books, unitOfWork);
     FillEditorial(category, categoryDTO.IdEditorial, unitOfWork);
 }
예제 #3
0
 static void InsertCategories(XmlDocument xmlDoc)
 {
     try
     {
         Console.WriteLine("Categoria de Programas");
         DTOCategory categoria  = new DTOCategory();
         XmlNodeList categories = xmlDoc.GetElementsByTagName("glf")[0].ChildNodes[0].ChildNodes[5].ChildNodes;
         int         i          = categories.Count;
         int         j          = 0;
         foreach (XmlNode category in categories)
         {
             categoria.IdCategory   = Int64.Parse(category.Attributes["id"].Value);
             categoria.MscName      = category.Attributes["mscname"].Value;
             categoria.CategoryName = category.Attributes["value"].Value;
             categoria.IdFather     = 0;
             conexion.AgregarCategoria(categoria);
             foreach (XmlNode subCategory in category.ChildNodes)
             {
                 categoria.IdCategory   = Int64.Parse(subCategory.Attributes["id"].Value);
                 categoria.MscName      = subCategory.Attributes["mscname"].Value;
                 categoria.CategoryName = subCategory.Attributes["value"].Value;
                 categoria.IdFather     = Int64.Parse(category.Attributes["id"].Value);
                 conexion.AgregarCategoria(categoria);
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
예제 #4
0
        public IActionResult Save(DTOCategory model)
        {
            if (!IsSet(model.Name))
            {
                ModelState.AddModelError(nameof(model.Name), _localizer.ErrNameIsRequired);
            }

            if (model.SelectedCategoryBrandsIds == null || model.SelectedCategoryBrandsIds.Count == 0)
            {
                ModelState.AddModelError(nameof(model.SelectedCategoryBrandsIds), _localizer.ErrBrandIsRequired);
            }

            if (!ModelState.IsValid)
            {
                model.CategoryBrandsListItems = _unitOfWork.Brands.GetAll().Select(x => new SelectListItem(x.Name, x.Id.ToString())).ToList();
                return(PartialView("AddEdit", model));
            }

            if (model.Id == 0)
            {
                _unitOfWork.Categories.Add(model);
            }
            else
            {
                _unitOfWork.Categories.Edit(model);
            }

            return(Json(new
            {
                success = true,
            }));
        }
예제 #5
0
        public IActionResult Add()
        {
            DTOCategory model = new DTOCategory();

            model.CategoryBrandsListItems = _unitOfWork.Brands.GetAll().Select(x => new SelectListItem(x.Name, x.Id.ToString())).ToList();

            return(PartialView("AddEdit", model));
        }
예제 #6
0
        public ActionResult <string> Put(string idRequest, long timestamp, [FromBody] DTOCategory categoryDTO)
        {
            CustomRequest          req             = new CustomRequest(idRequest, CustomRequest.FLAG_UPDATE, categoryDTO, categoryDTO.IdEditorial);
            CategoryRequestActions categoryRequest = new CategoryRequestActions(req, CustomScope);
            RequestManager         requestManager  = new RequestManager(timestamp, categoryRequest);

            requestPile.AddRequest(categoryDTO.IdEditorial, requestManager);
            return(Program.REQ_RESPONSE_POSITIVE);
        }
예제 #7
0
 public void CreateCategoryDTO(DTOCategory dtoaddcategory)
 {
     categoryRepository.CreateCategory(new Category
     {
         Id    = dtoaddcategory.Id,
         Name  = dtoaddcategory.Name,
         Badge = dtoaddcategory.Badge
     }
                                       );
 }
예제 #8
0
        public IActionResult Edit(int id)
        {
            if (id == 0)
            {
                return(RedirectToAction(nameof(Index)));
            }

            DTOCategory model = new DTOCategory();

            model = _unitOfWork.Categories.GetByIdDto(id);

            return(PartialView("AddEdit", model));
        }
예제 #9
0
        public void AgregarCategoria(DTOCategory category)
        {
            string sSel;
            string sSelCount;
            bool   exist;

            sSelCount = "SELECT COUNT(*) FROM \"tbl_ProgramCategory\" WHERE \"idCategory\"=" + category.IdCategory + "";
            NpgsqlDataAdapter daCount;
            DataSet           dtCount = new DataSet();

            try
            {
                daCount = new NpgsqlDataAdapter(sSelCount, sConexion);
                daCount.Fill(dtCount);
                if (dtCount.Tables[0].Rows[0][0].ToString() == "0")
                {
                    exist = false;
                }
                else
                {
                    exist = true;
                }
            }
            catch (Exception)
            {
                exist = false;
            }
            if (!exist)
            {
                if (category.IdFather != 0)
                {
                    sSel = "INSERT INTO \"tbl_ProgramCategory\" VALUES(" + category.IdCategory + ",'" + category.MscName + "','" + category.CategoryName + "'," + category.IdFather + ");";
                }
                else
                {
                    sSel = "INSERT INTO \"tbl_ProgramCategory\" VALUES(" + category.IdCategory + ",'" + category.MscName + "','" + category.CategoryName + "',-1)";
                }

                NpgsqlDataAdapter da;
                DataSet           dt = new DataSet();

                try
                {
                    da = new NpgsqlDataAdapter(sSel, sConexion);
                    da.Fill(dt);
                }
                catch (Exception)
                {
                }
            }
        }
        public void Edit(DTOCategory dtoCategory)
        {
            Category category = _mapper.Map <Category>(dtoCategory);

            _context.Update(category);

            List <int>           itemsToAdd     = dtoCategory.SelectedCategoryBrandsIds;
            List <int>           itemsToDelete  = new List <int>();
            List <CategoryBrand> categoryBrands = _context.CategoriesBrands.Where(x => x.CategoryId == category.Id).ToList();

            foreach (var item in categoryBrands)
            {
                bool exist = itemsToAdd.Any(x => x == item.BrandId);
                if (!exist)
                {
                    itemsToDelete.Add(item.Id);
                }
                else
                {
                    itemsToAdd.Remove(item.BrandId);
                }
            }

            if (itemsToDelete != null && itemsToDelete.Any())
            {
                foreach (var item in itemsToDelete)
                {
                    _unitOfWork.CategoriesBrands.Delete(item); //TODO : Ubaciti provjeru da li je povezan sa nekim postojecim PROIZVODOM
                }
            }



            if (itemsToAdd != null && itemsToAdd.Any())
            {
                CategoryBrand categoryBrand = null;

                foreach (var item in itemsToAdd)
                {
                    categoryBrand = new CategoryBrand
                    {
                        CategoryId = dtoCategory.Id,
                        BrandId    = item
                    };
                    _context.CategoriesBrands.Add(categoryBrand);
                }
            }
            _context.SaveChanges();
        }
예제 #11
0
        public CategoryRequestActions(CustomRequest request, CustomScope customScope)
        {
            Scope   = customScope;
            Request = request;
            CMapper = new CategoryMapper();

            if (request.Dto.GetType() == typeof(DTOCategory))
            {
                Dto = (DTOCategory)Convert.ChangeType(request.Dto, typeof(DTOCategory));
            }
            else
            {
                Dto = null;
            }
        }
예제 #12
0
        public Task <DataResult <DTOCategory> > GetCategoryByIdAsync(int id)
        {
            return(Task.Run(() =>
            {
                var categoryDTO = new DTOCategory();

                var category = categoryRepository.GetFirstOrDefault(x => x.Id == id, i => i.Parent);
                if (category != null)
                {
                    categoryDTO = _mapper.Map <DTOCategory>(category);
                }

                return new DataResult <DTOCategory> {
                    Errors = new List <ErrorDescriber>(), Target = categoryDTO
                };
            }));
        }
예제 #13
0
        public void CategoryDetailTest()
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(this.URLServer);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));

                HttpResponseMessage response = client.GetAsync("api/category/get/1").Result;
                Assert.IsTrue(response.IsSuccessStatusCode, "Error: Unable to Connect to Server");
                if (response.IsSuccessStatusCode)
                {
                    DTOCategory category = response.Content.ReadAsAsync <DTOCategory>().Result;
                    Assert.IsTrue(category != null, "Error: No Category Returned by Server");
                }
            }
        }
예제 #14
0
        public Task <DataResult <DTOCategory> > CreateCategoryAsync(DTOCategory categoryDTO)
        {
            return(Task.Run(() =>
            {
                var createdCategoryDTO = new DTOCategory();
                var categoryEntity = _mapper.Map <Category>(categoryDTO);

                if (!categoryRepository.ExistByCondition(x => x.Name == categoryEntity.Name))
                {
                    categoryEntity.ParentId = categoryEntity.ParentId > 0 ? categoryEntity.ParentId : null;
                    var createdCategoryEntity = categoryRepository.Insert(categoryEntity);
                    _unitOfWork.SaveChanges();

                    createdCategoryDTO = _mapper.Map <DTOCategory>(createdCategoryEntity);
                }

                return new DataResult <DTOCategory> {
                    Errors = new List <ErrorDescriber>(), Target = createdCategoryDTO
                };
            }));
        }
        public void Add(DTOCategory dtoCategory)
        {
            Category category = _mapper.Map <Category>(dtoCategory);

            _context.Add(category);
            _context.SaveChanges();

            CategoryBrand categoryBrand = null;

            foreach (var cb in dtoCategory.SelectedCategoryBrandsIds)
            {
                categoryBrand = new CategoryBrand
                {
                    CategoryId = category.Id,
                    BrandId    = cb
                };

                _context.CategoriesBrands.Add(categoryBrand);
            }

            _context.SaveChanges();
        }
예제 #16
0
        public async Task <IActionResult> GetCategory([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var category = await _context.Categories.Include(g => g.Games)
                           .FirstOrDefaultAsync(m => m.Id == id);

            DTOCategory dTOCategory = new DTOCategory()
            {
                Name = category.Name, NumGames = category.Games.Count
            };

            if (category == null)
            {
                return(NotFound());
            }

            return(Ok(dTOCategory));
        }
예제 #17
0
 public async Task <IHttpActionResult> Put([FromBody] DTOCategory categoryDTO)
 {
     return(await ExecuteServiceReturnDefaultResult(() => _serviceBuilder.Parameter.CategoryService.EditCategoryAsync(categoryDTO), false));
 }