Example #1
0
        public ItemDTO Create(CreateItemDTO model)
        {
            var item = _unitOfWork.Items.Create(new Item
            {
                Description = model.Description,
                Title       = model.Title,
                StepId      = model.StepId
            });

            _unitOfWork.SaveChanges();
            return(_mapper.Map <ItemDTO>(item));
        }
Example #2
0
        public ActionResult <ItemDTO> CreateItem(CreateItemDTO createItemDTO)
        {
            Item item = new()
            {
                Id          = Guid.NewGuid(),
                Name        = createItemDTO.Name,
                Price       = createItemDTO.Price,
                CreatedDate = DateTimeOffset.UtcNow
            };

            _repository.CreateItem(item);

            return(CreatedAtAction(nameof(GetItem), new { id = item.Id }, item.AsDTO()));
        }
Example #3
0
        public async Task <ActionResult <ItemDTO> > Post(CreateItemDTO createItemDTO)
        {
            var item = new Items
            {
                Name        = createItemDTO.Name,
                Description = createItemDTO.Description,
                Price       = createItemDTO.Price,
                CreatedDate = DateTimeOffset.UtcNow
            };

            await _itemsRepository.Create(item);

            await _publishEndpoint.Publish(new CatalogItemCreated(item.Id, item.Name, item.Description));

            return(CreatedAtAction(nameof(GetById), new { id = item.Id }, item));
        }
Example #4
0
        public async Task CreateItem_Creates(string name, string description)
        {
            var dto = new CreateItemDTO()
            {
                Name        = name,
                Description = description,
            };

            var result = await this.itemController.CreateItem(dto);

            var response = Assert.IsType <OkNegotiatedContentResult <ItemViewModel> >(result);

            Assert.Equal(name, response.Content.Name);
            Assert.Equal(description, response.Content.Description);
            Assert.True(response.Content.Id > 0);
        }
Example #5
0
        public async Task InsertItemAsync(CreateItemDTO model)
        {
            var createdBy = this.HttpContext.User.Claims.FirstOrDefault()?.Value;

            var item = new Item {
                Active        = model.Active,
                CreatedBy     = createdBy,
                Amount        = model.Amount,
                Brand         = model.Brand.ToLower(),
                Color         = model.Color.ToLower(),
                Description   = model.Description,
                Discount      = model.Discount,
                CategoryId    = model.Kind,
                Name          = model.Name,
                Price         = model.Price,
                Sex           = model.Sex,
                Size          = model.Size.ToLower(),
                Status        = model.Status,
                SubCategoryId = model.Subkind,

                PreviewImagePath = string.IsNullOrEmpty(model.PreviewImagePath)
                    ? "../ImageStore/default.png"
                    : await this.m_imageService.GetImagePathAsync(model.PreviewImagePath)
            };

            item.MinPreviewImagePath = string.IsNullOrEmpty(model.PreviewImagePath)
                ? "../ImageStore/default.png"
                : await this.m_imageService.GetMinImagePathAsync(item.PreviewImagePath);

            item.ImagePath1 = string.IsNullOrEmpty(model.ImagePath1) ? string.Empty : await this.m_imageService.GetImagePathAsync(model.ImagePath1);

            item.ImagePath2 = string.IsNullOrEmpty(model.ImagePath2) ? string.Empty : await this.m_imageService.GetImagePathAsync(model.ImagePath2);

            item.ImagePath3 = string.IsNullOrEmpty(model.ImagePath3) ? string.Empty : await this.m_imageService.GetImagePathAsync(model.ImagePath3);

            await this.Repository.CreateAsync(item);

            if (item.Id <= 0)
            {
                throw new Exception("Creating error.");
            }
        }
Example #6
0
        public IActionResult CreateItem(CreateItemViewModel item)
        {
            var dto = new CreateItemDTO();

            if (item.Create == true && item.Category != null && item.Name != null)
            {
                var file = Request.Form.Files.First();
                if (file != null)
                {
                    if (!Directory.Exists(Directory.GetCurrentDirectory() + "/wwwroot/images/items"))
                    {
                        Directory.CreateDirectory(Directory.GetCurrentDirectory() + "/wwwroot/images/items");
                    }
                    using (var fileStream = new FileStream(Directory.GetCurrentDirectory() + "/wwwroot/images/items/" + file.FileName, FileMode.Create))
                    {
                        file.CopyTo(fileStream);
                    }
                }
                foreach (var prop in item.GetType().GetProperties())
                {
                    if (prop.GetValue(item, null) != null)
                    {
                        if (dto.GetType().GetProperties().SingleOrDefault(x => x.Name == prop.Name) != null)
                        {
                            var propertyToModify = dto.GetType().GetProperties().SingleOrDefault(x => x.Name == prop.Name);
                            propertyToModify.SetValue(dto, prop.GetValue(item, null));
                        }
                    }
                }
                dto.PicturePath = file.FileName;
                this.itemService.CreateItem(dto);

                return(RedirectToAction("Index", "Home", new { message = "Termék sikeresen hozzáadva" }));
            }

            return(View(item));
        }
Example #7
0
        public async Task CreateItem_Creates()
        {
            var item = new CreateItemDTO()
            {
                Name = "Name", Description = "Description"
            };

            itemRepository.Setup(r => r.CreateAsync(It.IsAny <Item>(), It.IsAny <int>()))
            .Callback <Item, int>((i, u) => {
                i.Id          = 1;
                i.Name        = item.Name;
                i.Description = item.Description;
            });

            var createdItem = await this.itemService.CreateItemAsync(item, 123);

            this.itemRepository.Verify(r =>
                                       r.CreateAsync(It.Is <Item>(i =>
                                                                  i.Name == item.Name &&
                                                                  i.Description == item.Description), 123));
            Assert.Equal(1, createdItem.Id);
            Assert.Equal(item.Name, createdItem.Name);
            Assert.Equal(item.Description, createdItem.Description);
        }
Example #8
0
        public void CreateItem(CreateItemDTO item)
        {
            switch (EnumExtensionMethods.GetValueFromDescription <Category>(item.Category))
            {
            case Category.Cpu:
            {
                var cpu = new Cpu()
                {
                    Name             = item.Name,
                    Category         = Category.Cpu,
                    Available        = 20,
                    PicturePath      = item.PicturePath,
                    OriginalPrice    = item.OriginalPrice,
                    DiscountedPrice  = item.DiscountedPrice,
                    Manufacturer     = item.Manufacturer,
                    ShortDescription = item.ShortDescription,
                    Description      = item.Description,
                    Warranty         = item.Warranty,
                    GamingFlag       = item.GamingFlag,
                    IsUsed           = item.IsUsed,
                    HasRGB           = item.HasRGB,
                    DateSinceInStore = DateTime.Now,

                    BaseClock       = item.BaseClock.Value,
                    TDP             = item.TDP.Value,
                    ProcessorFamily = item.ProcessorFamily,
                    Technology      = item.Technology == null ? 0 : item.Technology.Value,
                    CoreNumber      = item.CoreNumber == null ? 0 : item.CoreNumber.Value,
                    ThreadNumber    = item.ThreadNumber == null ? 0 : item.ThreadNumber.Value,
                    Socket          = item.Socket
                };

                this.context.Items.Add(cpu);
                break;
            }

            case Category.Case:
            {
                var pcCase = new Case()
                {
                    Name             = item.Name,
                    Category         = Category.Cpu,
                    Available        = 20,
                    PicturePath      = item.PicturePath,
                    OriginalPrice    = item.OriginalPrice,
                    DiscountedPrice  = item.DiscountedPrice,
                    Manufacturer     = item.Manufacturer,
                    ShortDescription = item.ShortDescription,
                    Description      = item.Description,
                    Warranty         = item.Warranty,
                    GamingFlag       = item.GamingFlag,
                    IsUsed           = item.IsUsed,
                    HasRGB           = item.HasRGB,
                    DateSinceInStore = DateTime.Now,

                    BuiltInFanNumber     = item.BuiltInFanNumber == null ? 0 : item.BuiltInFanNumber.Value,
                    SupportedMotherboard = item.SupportedMotherboard,
                    Height    = item.Height == null ? 0 : item.Height.Value,
                    Width     = item.Width == null ? 0 : item.Width.Value,
                    Depth     = item.Depth == null ? 0 : item.Depth.Value,
                    HDDNumber = item.HDDNumber == null ? 0 : item.HDDNumber.Value,
                };

                this.context.Items.Add(pcCase);
                break;
            }
                //TODO: case for all types
            }
            context.SaveChanges();
        }