Exemplo n.º 1
0
        public ItemController(IItemRepository repository)
        {
            _repository = repository;

            var flourItem = new Item
            {
                Name     = "Flour",
                Quantity = new Quantity()
                {
                    Unit = "L", Total = 1
                }
            };

            _repository.Add(flourItem);
            var eggItem = new Item
            {
                Name     = "Egg",
                Quantity = new Quantity()
                {
                    Unit = "P", Total = 8
                }
            };

            _repository.Add(eggItem);

            _fridgeService = new FridgeService(_repository);
        }
Exemplo n.º 2
0
        public async Task ItemRepository_GetItems_Success()
        {
            // Arrange
            SetupEnvironment();

            var item = new Item()
            {
                Id          = "d3ab2dfa878227b15f1a0575",
                Name        = "Rose",
                Description = "Thorns",
                Price       = 12,
                Quantity    = 5
            };

            await _itemRepository.Add(item);

            // Act
            var result = await _itemRepository.GetAll();

            // Assert
            Assert.NotEmpty(result);
            Assert.Single(result.ToList());
            Assert.Equal(item.Id, result.First().Id);
            Assert.Equal(item.Name, result.First().Name);
            Assert.Equal(item.Id, result.First().Id);

            _context.DropDatabase();
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public long Add(object model)
        {
            try
            {
                var itemObj = (dynamic)model;

                var product = itemObj.ProductId == null?
                              _productService.GetByProductCode(itemObj.ProductCode.Value) : null;

                var brand = itemObj.BrandId == null?
                            _brandService.GetByBrandCode(((dynamic)itemObj).BrandCode.Value) : null;

                var item = new Item
                {
                    CustomerId   = itemObj.CustomerId != null ? itemObj.CustomerId.Value : null,
                    ProductId    = itemObj.ProductId != null ? itemObj.ProductId.Value : product.Id,
                    BrandId      = itemObj.BrandId != null ? itemObj.BrandId.Value : brand.Id,
                    ItemCode     = itemObj.ItemCode != null ? itemObj.ItemCode.Value : "",
                    Description  = itemObj.Description != null ? itemObj.Description.Value : "",
                    ReceivedBy   = itemObj.ReceivedBy != null ? itemObj.ReceivedBy.Value : "",
                    ReceivedDate = itemObj.ReceivedDate != null ? itemObj.ReceivedDate.Value : (DateTime?)null,
                    ExpiryDate   = itemObj.ExpiryDate != null ? itemObj.ExpiryDate.Value : (DateTime?)null,
                    CreatedBy    = itemObj.CreatedBy != null ? itemObj.CreatedBy.Value : ""
                };

                long retId = 0;

                if (IsDuplicate(item.ItemCode, item.Id, item.CustomerId) == false)
                {
                    retId = _itemRepository.Add(item);
                }
                else
                {
                    Expression <Func <Item, bool> > res = x => x.ItemCode == item.ItemCode && x.CustomerId == item.CustomerId && x.IsActive == false;
                    var obj = _itemRepository.Get(res);

                    if (obj != null)
                    {
                        retId = obj.Id;

                        item.Id       = retId;
                        item.IsActive = true;

                        _itemRepository.Detach(obj);

                        _itemRepository.Update(item);

                        //return item.Id;
                    }
                }

                return(retId);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 4
0
        public ItemViewModel AddItem(ItemViewModel item)
        {
            var newItem = ItemMapper.MapModelToEntity(item);

            newItem.CreatedBy = "TEST";
            newItem.SeedData  = false;
            var addedItem = _itemRepository.Add(newItem);

            return(ItemMapper.MapEntityToModel(addedItem));
        }
Exemplo n.º 5
0
 public void SaveItem(Item item)
 {
     if (item.ItemID > 0)
     {
         ItemRepo.Update(item);
     }
     else
     {
         ItemRepo.Add(item);
     }
     ItemRepo.SaveChanges();
 }
Exemplo n.º 6
0
        public void AddItem(Item newItem)
        {
            List <Item> data = new List <Item>();

            data = _itemRepository.GetItems(); // fetch the entire database
            int Total = data.Where(x => x.AvailableDate == newItem.AvailableDate).Count();
            var count = 0;
            var flag  = 0;

            if (Total < 15)
            {
                foreach (var Element in data)
                {
                    if (Element.ItemName == newItem.ItemName)
                    {
                        break;
                        // " with same name already exist for the date";
                    }

                    else
                    {
                        flag = 1;
                    }
                }
            }

            if (flag == 1)
            {
                if (newItem.IsSpecial == true)
                {
                    foreach (var Element in data)
                    {
                        if (Element.AvailableDate == newItem.AvailableDate)
                        {
                            if (Element.IsSpecial == true)
                            {
                                count++;
                            }
                        }
                    }

                    if (count < 4)
                    {
                        _itemRepository.Add(newItem);
                    }
                }

                else
                {
                    _itemRepository.Add(newItem);
                }
            }
        }
Exemplo n.º 7
0
        public Quantity AddItem(Item item)
        {
            _repository.Add(item);
            List <Item> items = _repository.GetAll();

            return(items.FirstOrDefault(x => x.Name == item.Name).Quantity);
        }
Exemplo n.º 8
0
 public IActionResult AddNewItem(Item item)
 {
     item.ImgPath = imgPath;
     _itemRepository.Add(item);
     _itemRepository.Commit();
     return(RedirectToAction("Details", new { id = item.Id }));
 }
Exemplo n.º 9
0
        public async Task <Guid> Handle(CreateItem command)
        {
            var id = Guid.NewGuid();
            await _repo.Add(new Item(id, command.Name, command.Description, command.Traits));

            return(id);
        }
Exemplo n.º 10
0
        public Item Add(Item Item)
        {
            var item = _ItemRepository.Add(Item);

            _unitOfWork.Commit();
            if (!string.IsNullOrEmpty(Item.Tags))
            {
                string[] tags = Item.Tags.Split(',');
                for (var i = 0; i < tags.Length; i++)
                {
                    var tagId = StringHelper.ToUnsignString(tags[i]);
                    if (_tagRepository.Count(x => x.ID == tagId) == 0)
                    {
                        Tag tag = new Tag();
                        tag.ID   = tagId;
                        tag.Name = tags[i];
                        tag.Type = CommonConstants.ProductTag;
                        _tagRepository.Add(tag);
                    }

                    ProductTag productTag = new ProductTag();
                    productTag.ProductID = Item.ID;
                    productTag.TagID     = tagId;
                    _ItemTagRepository.Add(productTag);
                }
            }
            return(Item);
        }
Exemplo n.º 11
0
        public Result <Item> Add(Item item)
        {
            var result = new Result <Item>();

            if (item == null)
            {
                result.AddMessage("Item must not be null.");
                return(result);
            }

            if (string.IsNullOrWhiteSpace(item.Name))
            {
                result.AddMessage("Item name is required.");
            }
            else if (repository.FindAll()
                     .Any(i => i.Name.Equals(item.Name, StringComparison.OrdinalIgnoreCase)))
            {
                result.AddMessage($"Item '{item.Name}' is a duplicate.");
            }

            if (item.DollarsPerKilogram < 0M || item.DollarsPerKilogram > 7500M)
            {
                result.AddMessage("$/Kg must be between 0.00 and 7500.00.");
            }

            if (!result.Success)
            {
                return(result);
            }

            result.Value = repository.Add(item);

            return(result);
        }
Exemplo n.º 12
0
        public Task Handle(AddNewItemCommand request, CancellationToken cancellationToken)
        {
            var item = new Item();

            item.Name        = request.Name;
            item.Description = request.Description;
            item.Price       = request.Price;

            var category = _categoryRepository.GetById(request.CategoryId);

            item.Category = category;

            var itemValues = new List <ItemValue>();

            for (var i = 0; i < request.CategoryFieldIds.Count; i++)
            {
                var categoryField = _categoryFieldRepository.GetById(request.CategoryFieldIds[i]);
                itemValues.Add(new ItemValue
                {
                    Field      = categoryField,
                    FieldValue = request.FieldValues[i]
                });
            }
            item.ItemValues = itemValues;

            _itemRepository.Add(item);
            Commit();

            return(Task.CompletedTask);
        }
Exemplo n.º 13
0
        public Item EnsureItemWithUnit(string itemDescription)
        {
            itemDescription = itemDescription ?? "";

            var parts = itemDescription.Split(',');

            string name = parts[0].Trim();
            string unit = parts.Count() > 1 ? parts[1] : null;

            if (string.IsNullOrWhiteSpace(name))
            {
                throw new Exception($"Incorrect item description provided: {itemDescription}");
            }

            var entity = _rep.GetByText(name);

            if (entity == null)
            {
                entity = new ItemEntity
                {
                    Text = name,
                    Unit = CodeUtils.CreateCode(unit),
                    Code = CodeUtils.CreateCode(name)
                };
                _rep.Add(entity);
            }

            return(ItemMapper.MapToModel(entity));
        }
Exemplo n.º 14
0
        public IActionResult CreateItem(ItemCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = ProcessUploadedFile(model);

                Item newItem = new Item
                {
                    Category           = model.Category,
                    Name               = model.Name,
                    shortDescription   = model.shortDescription,
                    LongDescription    = model.LongDescription,
                    AllergyInformation = model.AllergyInformation,
                    Price              = model.Price,
                    Discount           = model.Discount,
                    Size               = model.Size,
                    Quantity           = model.Quantity,
                    UnitsInOrder       = model.UnitsInOrder,
                    isItemOfTheWeek    = model.isItemOfTheWeek,
                    InStock            = model.InStock,
                    Customise          = model.Customise,
                    CustomisedType     = model.CustomisedType,
                    CustomisedOption   = model.CustomisedOption,
                    Discontinued       = model.Discontinued
                };

                _itemRepository.Add(newItem);
                return(RedirectToAction("Details", new { id = newItem.ItemId }));
            }
            return(View());
        }
Exemplo n.º 15
0
 public void Post(List <Item> entity)
 {
     if (ModelState.IsValid)
     {
         _repository.Add(entity);
     }
 }
Exemplo n.º 16
0
        public IActionResult OnPost()
        {
            if (ModelState.IsValid)
            {
                Item.Topics    = Topics;
                Item.Consumers = Consumers;

                if (ScreenShotPhoto != null)
                {
                    if (Item.ScreenShotPath != null)
                    {
                        string filePath = Path.Combine(webHostEnvironment.WebRootPath, "catalogScreenShots", Item.ScreenShotPath);
                        System.IO.File.Delete(filePath);
                    }
                    Item.ScreenShotPath = ProcessUploadedFile(ScreenShotPhoto);
                }

                if (Item.Id > 0)
                {
                    Item = itemRepository.Update(Item);
                }
                else
                {
                    Item = itemRepository.Add(Item);
                }

                return(RedirectToPage("index"));
            }

            // In the event there are validation issues we can re-render the page
            // so the user can correct any errors.
            return(Page());
        }
Exemplo n.º 17
0
        public IActionResult Create([FromBody] TMeasurement item)
        {
            try
            {
                if (item == null || !ModelState.IsValid)
                {
                    return(BadRequest("Invalid State"));
                }

                ItemRepository.Add(item);
            }
            catch (Exception)
            {
                return(BadRequest("Error while creating"));
            }
            return(Ok(item));
        }
Exemplo n.º 18
0
    public async Task <ItemResponse> AddItemAsync(AddItemRequest request)
    {
        var item   = _itemMapper.Map(request);
        var result = _itemRepository.Add(item);
        await _itemRepository.UnitOfWork.SaveChangesAsync();

        return(_itemMapper.Map(result));
    }
Exemplo n.º 19
0
 public async Task <IActionResult> CreateEntity([FromBody] ItemEntity item)
 {
     Console.WriteLine("Adding item with title: " + item.Title);
     item.DateCreated = DateTime.Now;
     _dbLogic.Add(item);
     _dbLogic.GenerateTags(item);
     unitOfWork.Commit();
     return(Ok(item));
 }
Exemplo n.º 20
0
        public async Task <IActionResult> Post([FromBody] ItemViewModel itemViewModel)
        {
            var item = mapper.Map <Item>(itemViewModel);

            itemRepository.Add(item, User.GetMuseumId());
            await unitOfWork.SaveChangesAsync();

            return(Ok(mapper.Map <ItemViewModel>(item)));
        }
Exemplo n.º 21
0
 public DomainItem CreateEntity(DomainItemUpdateModel item)
 {
     validator.ValidatePlayer(item);
     if (item == null)
     {
         throw new ArgumentNullException("Item is null");
     }
     return(itemDB.Add(item));
 }
Exemplo n.º 22
0
        public IActionResult AddItem(string value)
        {
            if (!string.IsNullOrEmpty(value))
            {
                itemRepository.Add(value);
            }

            return(RedirectToAction("Todo"));
        }
Exemplo n.º 23
0
 public Item Add(Item item)
 {
     item.Id = Guid.NewGuid();
     if (Validate(item))
     {
         return(_itemRepository.Add(item));
     }
     return(null);
 }
        public async Task <IActionResult> Post(ItemForAddDTO model)
        {
            Item item = mapper.Map <Item>(model);
            await itemRepository.Add(item).ConfigureAwait(true);

            await unitOfWork.CompleteAsync().ConfigureAwait(true);

            return(Ok(mapper.Map <ItemForGetDTO>(await itemRepository.Get(item.Id).ConfigureAwait(true))));
        }
Exemplo n.º 25
0
        public async Task <ItemResponse> Handle(AddItemCommand command, CancellationToken cancellationToken)
        {
            var item = _mapper.Map <Entities.Item>(command);

            var result = _itemRepository.Add(item);
            await _itemRepository.UnitOfWork.SaveChangesAsync(cancellationToken);

            return(_mapper.Map <ItemResponse>(result));
        }
Exemplo n.º 26
0
 public ActionResult Create(LoanItem loanItem)
 {
     if (!ModelState.IsValid)
     {
         return(View("Create", loanItem));
     }
     _itemRepository.Add(loanItem);
     return(RedirectToAction("Index"));
 }
Exemplo n.º 27
0
        public ValidationResult Add(Item item)
        {
            if (!item.IsValid)
            {
                return(item.ValidationErrors.ToValidationResult());
            }

            _validationResult.Entity = _repository.Add(item);
            return(_validationResult);
        }
Exemplo n.º 28
0
        public async Task <ItemResponse> Add(ItemRequest itemRequest)
        {
            var item = _mapper.Map <Item>(itemRequest);

            await _itemRepository.Add(item);

            var itemResponse = _mapper.Map <ItemResponse>(item);

            return(itemResponse);
        }
Exemplo n.º 29
0
        /// <summary>
        /// This method adds a person to the server side repository.
        /// </summary>
        /// <param name="person">The person to add</param>
        /// <returns>A response message with the new id of the person added</returns>
        public HttpResponseMessage PostPerson(Person person)
        {
            person = repository.Add(person);
            var response = Request.CreateResponse(HttpStatusCode.Created, person);

            string uri = Url.Link("DefaultApi", new { id = person.Id });

            response.Headers.Location = new Uri(uri);
            return(response);
        }
Exemplo n.º 30
0
        public Item Add(Item newItem)
        {
            Item resource = _itemRepo.Add(newItem);

            if (resource == null)
            {
                throw new ApplicationException("That resource already exists. You can't create a duplicate of the same resource.");
            }

            return(resource);
        }