Exemplo n.º 1
0
        public PipelineExecutionResult Execute(Category subject)
        {
            var idToDelete = subject.Name;

            logging.Log <DeleteCategoryFromKaching>("Deleting tag: " + subject.Name + " in Ka-ching");
            var config = KachingConfiguration.Get();
            var url    = config.TagsIntegrationURL;

            if (url.StartsWith("https://", StringComparison.Ordinal))
            {
                var idsToDelete = new List <string>();
                idsToDelete.Add(idToDelete);
                var result = Synchronizer.Delete(idsToDelete, url);
                if (result == PipelineExecutionResult.Error)
                {
                    return(result);
                }
            }


            var folders    = new CategoryConverter(logging).GetFolders();
            var foldersUrl = config.FoldersIntegrationURL;

            if (!foldersUrl.StartsWith("https://", StringComparison.Ordinal))
            {
                return(PipelineExecutionResult.Success);
            }
            return(Synchronizer.Post(folders, foldersUrl));
        }
        public IHttpActionResult PostCategory(CategoryDTO category)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            Category c = CategoryConverter.DTOToDAL(category);

            CategoryBLL.Add(c);

            try
            {
                Global.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (CategoryExists(category.code))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = category.code }, category));
        }
Exemplo n.º 3
0
        public void should_convert_from_string(string input, string expected)
        {
            var converter = new CategoryConverter();
            var result    = converter.ConvertFromString(input, Mock.Of <IReaderRow>(), null);

            result.Should().Be(expected);
        }
Exemplo n.º 4
0
        public async Task <CategoryDto> Create(CategoryDto item)
        {
            var cat = await FindByTitle(item.Title);

            if (cat != null)
            {
                return(cat);
            }
            if (item.Title == "" || item.Title == null)
            {
                return(null);
            }
            var result = await _context.Categories.AddAsync(new Category { Title = item.Title });

            await _context.SaveChangesAsync();

            if (result.Entity != null)
            {
                return(CategoryConverter.Convert((result.Entity)));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 5
0
        public List <CategoryModel> GetAllCategories()
        {
            var entities = _iCategoryDAO.GetAllCategories();
            var models   = CategoryConverter.EntitiesToModels(entities);

            return(models);
        }
Exemplo n.º 6
0
 public static List <CategoryDTO> GetCategories()
 {
     using (GetCoffeeDBEntities db = new GetCoffeeDBEntities())
     {
         return(CategoryConverter.DALListToDTO(db.Categories.ToList()));
     }
 }
Exemplo n.º 7
0
 public static CategoryDTO GetCategoryById(long id)
 {
     using (GetCoffeeDBEntities db = new GetCoffeeDBEntities())
     {
         return(CategoryConverter.DALToDTO(db.Categories.Find(id)));
     }
 }
Exemplo n.º 8
0
        public async Task <CategoryDTO> Add(CreateCategoryDTO categoryDTO)
        {
            if (categoryDTO == null)
            {
                return(null);
            }

            if (categoryDTO.ParentCategoryId != null && await Get(categoryDTO.ParentCategoryId.Value) == null)
            {
                return(null);
            }

            var entity = await unitOfWork.Repository <Category>().Add(CategoryConverter.Convert(categoryDTO));


            if (entity == null)
            {
                return(null);
            }
            if (entity.ParentCategoryId != null)
            {
                entity.ParentCategory = await unitOfWork.Repository <Category>().Get(entity.ParentCategoryId.Value);
            }
            return(CategoryConverter.Convert(entity));
        }
Exemplo n.º 9
0
        public async Task <bool> Update(CategoryDto item)
        {
            _context.Categories.Update(CategoryConverter.Convert(item));
            await _context.SaveChangesAsync();

            return(true);
        }
Exemplo n.º 10
0
        public void Read_multiple()
        {
            // Arrange
            var json = "['category1','category2','category3']";

            var textReader    = new StringReader(json);
            var jsonReader    = new JsonTextReader(textReader);
            var objectType    = (Type)null;
            var existingValue = (object)null;
            var serializer    = new JsonSerializer();

            var converter = new CategoryConverter();

            // Act
            jsonReader.Read();
            var result = converter.ReadJson(jsonReader, objectType, existingValue, serializer);

            // Assert
            result.ShouldNotBeNull();
            result.ShouldBeOfType <string[]>();

            var resultAsArray = (string[])result;

            resultAsArray.Length.ShouldBe(3);
            resultAsArray[0].ShouldBe("category1");
            resultAsArray[1].ShouldBe("category2");
            resultAsArray[2].ShouldBe("category3");
        }
Exemplo n.º 11
0
        public async Task <List <CategoryDto> > GetAllAsync()
        {
            var categories = CategoryConverter.Convert(
                await _context.Categories
                .ToListAsync());

            return(categories);
        }
Exemplo n.º 12
0
 public async Task <CategoryDto> GetByIdAsync(int id)
 {
     return(CategoryConverter.Convert(
                await _context.Categories
                // .Include(c => c.PostCategory)
                // .ThenInclude(pc => pc.Post)
                .FirstOrDefaultAsync(c => c.Id == id)));
 }
Exemplo n.º 13
0
        public async Task <CategoryDto> CreateAsync(CategoryDto item)
        {
            var category = _context.Categories.Add(
                CategoryConverter.Convert(item));
            await _context.SaveChangesAsync();

            return(CategoryConverter.Convert(category.Entity));
        }
Exemplo n.º 14
0
        public void CanConvert()
        {
            // Act
            var converter = new CategoryConverter();

            // Assert
            converter.CanConvert(null).ShouldBeTrue();
        }
Exemplo n.º 15
0
        public async Task <CategoryDto> Create(CategoryDto item)
        {
            var result = await _context.Categories.AddAsync(CategoryConverter.Convert(item));

            await _context.SaveChangesAsync();

            return(CategoryConverter.Convert(result.Entity));
        }
Exemplo n.º 16
0
        public async Task <ItemDto> GetById(Guid id)
        {
            var item     = ItemConverter.Convert(_context.Items.AsNoTracking().First(x => x.Id == id));
            var category = CategoryConverter.Convert(_context.Categories.AsNoTracking().First(x => x.Id == item.CategoryId));

            item.Category     = category;
            item.CategoryName = category.Name;
            return(item);
        }
Exemplo n.º 17
0
        public void Properties()
        {
            // Act
            var converter = new CategoryConverter();

            // Assert
            converter.CanRead.ShouldBeTrue();
            converter.CanWrite.ShouldBeFalse();
        }
Exemplo n.º 18
0
 public CourseService(IDataFacade facade)
 {
     _crsConv      = new CourseConverter();
     _userConv     = new UserConverter();
     _secConverter = new SectionConverter();
     _catConv      = new CategoryConverter();
     _lesConv      = new LessonConverter();
     _facade       = facade;
 }
        private List <int> ConverComingCategories(List <string> comingCategories)
        {
            List <int> categories = new List <int>();

            foreach (string comingCategory in comingCategories)
            {
                categories.Add((int)CategoryConverter.RusStringToEnum(comingCategory));
            }
            return(categories);
        }
Exemplo n.º 20
0
        public async Task <CategoryDTO> Get(long id)
        {
            var category = await GetCategoryEntity(id);

            if (category == null)
            {
                return(null);
            }
            return(CategoryConverter.Convert(category));
        }
Exemplo n.º 21
0
        public async Task <List <CategoryDTO> > GetCategories()
        {
            var categories = unitOfWork.Repository <Category>().GetQueryable().ToList();

            if (categories == null)
            {
                return(null);
            }
            return(await Task.FromResult(CategoryConverter.Convert(categories)));
        }
Exemplo n.º 22
0
        public async Task <CategoryDTO> Get(long id)
        {
            var category = await unitOfWork.Repository <Category>().Get(id);

            if (category == null)
            {
                return(null);
            }
            return(CategoryConverter.Convert(category));
        }
Exemplo n.º 23
0
        private DbProduct SetProductData(AddEditProduct productFromView)
        {
            DbProduct newDbProduct = new DbProduct();

            newDbProduct.DbProductId       = String.IsNullOrEmpty(productFromView.ProductId) ? GeneratorId.GenerateId() : productFromView.ProductId;
            newDbProduct.DbProductName     = productFromView.ProductName;
            newDbProduct.DbProductWeight   = Decimal.Parse(productFromView.ProductWeight.Replace(".", ","));
            newDbProduct.DbProductCategory = (int)CategoryConverter.RusStringToEnum(productFromView.ProductCategory);
            newDbProduct.DbImageRes        = productFromView.ProductImageRes;
            return(newDbProduct);
        }
Exemplo n.º 24
0
        public async Task CreateAsync(Category entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            var category = CategoryConverter.Convert(entity);

            await _session.InsertAsync(category);
        }
Exemplo n.º 25
0
 public async Task <CategoryDto> FindByTitle(string title)
 {
     try
     {
         return(CategoryConverter.Convert(await _context.Categories.FirstOrDefaultAsync(a => a.Title.ToLower() == title.ToLower())));
     }
     catch
     {
         return(null);
     }
 }
Exemplo n.º 26
0
        public async Task <List <ItemDto> > GetByCategory(Guid id)
        {
            var category = CategoryConverter.Convert(_context.Categories.AsNoTracking().FirstOrDefault(x => x.Id == id));
            var items    = ItemConverter.Convert(_context.Items.AsNoTracking().ToList().FindAll(x => x.CategoryId == id));

            foreach (var item in items)
            {
                item.Category     = category;
                item.CategoryName = category.Name;
            }
            return(items);
        }
Exemplo n.º 27
0
        public async Task <CategoryDTO> Update(UpdateCategoryDTO dto) // update dto
        {
            if (dto == null)
            {
                return(null);
            }
            var entity = CategoryConverter.Convert(dto);

            entity = await unitOfWork.Repository <Category>().Update(entity);

            return(CategoryConverter.Convert(entity));
        }
Exemplo n.º 28
0
        public void Write()
        {
            // Arrange
            var writer     = (JsonWriter)null;
            var value      = (object)null;
            var serializer = (JsonSerializer)null;

            var converter = new CategoryConverter();

            // Act
            Should.Throw <NotImplementedException>(() => converter.WriteJson(writer, value, serializer));
        }
Exemplo n.º 29
0
        public async Task <List <CategoryDTO> > GetAll()
        {
            var categories = unitOfWork.Repository <Category>().GetQueryable()
                             .Include(x => x.ParentCategory)
                             .Where(x => x.IsDeleted != true)
                             .ToList();

            if (categories == null)
            {
                return(null);
            }
            return(await Task.FromResult(CategoryConverter.Convert(categories)));
        }
        protected void StartCategoryImportButton_Click(Object sender, EventArgs e)
        {
            var converter = new CategoryConverter(logger);
            var folders   = converter.GetFolders();
            var tags      = converter.GetAllTags();

            PostFolders(folders);
            PostTags(tags);

            var count = tags.Count;

            ImportStatus.Text = $"Initiated export of {count} categories.";
        }