Exemple #1
0
        public IActionResult Add([FromForm] ItemRequest item)
        {
            var validator        = new ItemValidator();
            var validationResult = validator.Validate(item);

            if (validationResult.IsValid)
            {
                var newItem = _mapper.Map <Item>(item);
                _itemService.Add(newItem);
                return(Ok());
            }
            return(BadRequest());
        }
Exemple #2
0
        public IHttpActionResult Add(object model)
        {
            long retId;

            try
            {
                retId = _itemService.Add(model);

                if (retId == 0)
                {
                    Log.Info($"{typeof(ItemController).FullName}||{UserEnvironment}||Add record not successful, Item Code is duplicate.");
                    return(Content(HttpStatusCode.Forbidden, "Item Code is Duplicate"));
                }
                Log.Info($"{typeof(ItemController).FullName}||{UserEnvironment}||Add record successful.");

                var    response = this.Request.CreateResponse(HttpStatusCode.Created);
                string test     = JsonConvert.SerializeObject(new
                {
                    id      = retId,
                    message = "Item added"
                });
                response.Content = new StringContent(test, Encoding.UTF8, "appliation/json");
                Log.Info($"{typeof(ItemController).FullName}||{UserEnvironment}||Add record successful.");

                return(ResponseMessage(response));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemple #3
0
        public async Task <IActionResult> Edit(ItemViewModel item, [FromForm] List <IFormFile> formFiles)
        {
            var user = _userManager.GetUserAsync(User).Result;

            item.UserId     = user.Id;
            item.CreateDate = DateTime.Now;
            if (item.Id == 0)
            {
                var addedItem = await _itemService.Add(_mapper.Map <ItemDto>(item));

                ItemImageHelper helper = new ItemImageHelper(_itemImageService, _hostingEnvironment);
                if (formFiles != null && formFiles.Count > 0)
                {
                    await helper.SaveProductImage(formFiles, addedItem.Id);
                }
                return(RedirectToAction("Index", new { id = addedItem.Id }));
            }
            else
            {
                if (await CheckUserId(item.UserId))
                {
                    return(RedirectToAction("Index", "Home"));
                }
                await _itemService.Update(_mapper.Map <ItemDto>(item));

                ItemImageHelper helper = new ItemImageHelper(_itemImageService, _hostingEnvironment);
                if (formFiles != null && formFiles.Count > 0)
                {
                    await helper.SaveProductImage(formFiles, item.Id);
                }
                return(RedirectToAction("Index", new { id = item.Id }));
            }
        }
Exemple #4
0
        public HttpResponseMessage Create(HttpRequestMessage request, itemViewModel productCategoryVm)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var newProduct = new Item();
                    newProduct.UpdateProduct(productCategoryVm);
                    newProduct.CreatedDate = DateTime.Now;
                    newProduct.CreatedBy = User.Identity.Name;
                    _productService.Add(newProduct);
                    _productService.Save();

                    var responseData = Mapper.Map <Item, itemViewModel>(newProduct);
                    response = request.CreateResponse(HttpStatusCode.Created, responseData);
                }

                return response;
            }));
        }
Exemple #5
0
        public ActionResult Step1(Item item, string ModeID)
        {
            IList <ItemMode> lt = new List <ItemMode>();

            string[] st = ModeID.Split(',');
            st.ToList().ForEach(p => lt.Add(new ItemMode()
            {
                ModeID = Convert.ToInt32(p)
            }));

            if (item.Id == -1)
            {
                //判断
                if ((Convert.ToDateTime("2016-07-25") - DateTime.Now).Days <= 0)
                {
                    return(Json(new { code = 500, message = "对不起,软件使用期限即将到期,请联系管理员注册!", id = item.Id }));
                }
                item.InputPerson = UserId;
                item.InputTime   = DateTime.Now;
                item.IsUpdate    = false;
                _itemService.Add(item, lt.ToList());
            }
            else
            {
                item = _itemService.Update(item, lt.ToList());
            }
            return(Json(new { code = 200, message = "数据保存成功!", id = item.Id }));
        }
Exemple #6
0
        public async Task <ItemDTO> Add(ItemDTO objeto)
        {
            var map = _mapper.Map <ItemDTO, Item>(objeto);
            await _itemService.Add(map);

            var retorno = List().Result.OrderByDescending(o => o.ItemId).FirstOrDefault();

            return(retorno);
        }
        public async Task AddItem(ItemCreateRequest request, string gameCode)
        {
            int.TryParse(Context.Items[KeyConstants.GameCode] as string, out int gameId);
            await _itemService.Add(request, gameId);

            var items = await _itemService.GetItemsByGameId(gameId);

            await Clients.Group(gameCode).RefreshItemList(items);
        }
 public async Task <IActionResult> Create([Bind("Id,Name,ItemTypeId,IsAvailable")] Item item)
 {
     if (ModelState.IsValid)
     {
         _itemService.Add(item);
         return(RedirectToAction(nameof(Index)));
     }
     ViewData["ItemTypeId"] = new SelectList(_itemTypeService.GetAll(), "Id", "Name", item.ItemTypeId);
     return(View(item));
 }
Exemple #9
0
        public IActionResult Post([FromBody] ItemDto item)
        {
            if (ModelState.IsValid)
            {
                _itemsService.Add(item);
                return(Ok(true));
            }

            return(BadRequest(ModelState));
        }
Exemple #10
0
        public ActionResult Index(ItemVM item)
        {
            if (!IsAdmin())
            {
                return(Redirect("/"));
            }
            Guid itemId = _itemService.Add(_itemMapper.ConvertFromVM(item)).Id;

            _pictureService.Add(item.Images, itemId);
            return(Redirect("/Admin"));
        }
Exemple #11
0
 public ActionResult Step1(Item item)
 {
     item.ItemMode    = 1;
     item.InputPerson = 1;
     item.ItemNo      = "1";
     item.File1       = "1";
     item.File2       = "1";
     item.InputTime   = DateTime.Now;
     _itemService.Add(item);
     return(Json(new { code = 200, message = "询价工程发布成功!" }));
 }
Exemple #12
0
        public IActionResult Post([FromBody] AddItemDto model)
        {
            if (!ModelState.IsValid)
            {
                NotifyModelStateErrors();
                return(Response(model));
            }

            _itemService.Add(model);

            return(Response(model));
        }
        public IActionResult Post([FromBody] ItemDto item)
        {
            if (item == null || ModelState.IsValid == false)
            {
                return(BadRequest(ModelState));
            }

            var itemId  = itemService.Add(item);
            var itemDto = itemService.Get(itemId);

            return(CreatedAtAction("Get", new { id = itemId }, itemDto));
        }
Exemple #14
0
        public ItemVM Add(ItemVM itemVm)
        {
            var item = Mapper.Map <ItemVM, Item>(itemVm);

            ObjectUtils.CheckNullObj(item);

            _uow.BeginTransaction();
            _itemService.Add(item);

            _uow.Commit();

            return(itemVm);
        }
Exemple #15
0
        public async Task Should_add_an_item()
        {
            //Arrange
            _itemService.Add(_itemRequest).Returns(_itemResponse);

            //Act
            var result = await _itemsController.Add(_itemRequest);

            //Assert
            await _itemService.Received(1).Add(_itemRequest);

            result.Should().BeOfType <CreatedResult>();
        }
Exemple #16
0
        private void AddItem()
        {
            ItemConfirmation y = new ItemConfirmation();

            NewItemRequest.Raise(y, x =>
            {
                if (x.Confirmed)
                {
                    _itemService.Add(x.Item);
                    OnItemAdded(x.Item);
                }
            });
        }
        public ValidationResult Add(Item item)
        {
            BeginTransaction();

            var itemModel = item.ToModel();

            ValidationResult = _itemService.Add(itemModel).ToViewModel();

            if (ValidationResult.IsValid)
            {
                Commit();
            }
            return(ValidationResult);
        }
Exemple #18
0
        [ServiceFilter(typeof(ValidateEntityAccess))] //put groupId as first parameter, as filter will take it as entity name to be validated.
        public IActionResult CreateItem(int groupId, [FromBody] ItemVM itemModel)
        {
            var itemServiceModel = _mapper.Map <ItemServiceModel>(itemModel);
            var result           = _itemService.Add(itemServiceModel, _currentUserId, groupId);

            if (result.IsSuccess)
            {
                var itemViewModel = _mapper.Map <ItemVM>(result.Data);
                return(CreatedAtAction("GetItemById", new { itemId = itemViewModel.Id }, itemViewModel)); //return 201 Created with http location header
            }
            else
            {
                return(new StatusCodeResult(result.StatusCodes));
            }
        }
Exemple #19
0
 private void AddItem()
 {
     ItemEditRequest.Raise(new ItemConfirmation(new Item(), SelectedCategory), x =>
     {
         if (x.Confirmed)
         {
             _itemService.Add(x.Item);
             if (SelectedCategory.ID == x.Category.ID)
             {
                 Items.Add(x.Item);
                 SelectedItem = x.Item;
             }
         }
     });
 }
Exemple #20
0
        public async Task <IActionResult> Create([FromBody, Required] ItemDto item)
        {
            var itemBusiness = _mapper.Map <Item>(item);

            try
            {
                await _itemService.Add(itemBusiness);

                return(NoContent());
            }
            catch (Exception)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }
Exemple #21
0
        public IActionResult EditItem(Item item)
        {
            if (item.ItemId == 0)
            {
                TempData["SuccessBannerMessage"] = "Item successfully added.";
                _itemService.Add(item);
            }
            else
            {
                TempData["SuccessBannerMessage"] = "Item successfully updated.";
                _itemService.Edit(item);
            }

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult <ItemViewModel> > Add(ItemViewModel itemModel)
        {
            if (!ModelState.IsValid)
            {
                return(CustomResponse(ModelState));
            }

            var item = _mapper.Map <Item>(itemModel);

            item = await _itemService.Add(item);

            itemModel = _mapper.Map <ItemViewModel>(item);

            return(CustomResponse(itemModel));
        }
Exemple #23
0
        public IHttpActionResult Post([FromBody] ItemDto item)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            item.Id = _itemService.Add(item.ToEntity());
            if (item.Id > 0)
            {
                string uri = Url.Link("DefaultApi", new { id = item.Id });
                return(Created(uri, item));
            }

            return(BadRequest());
        }
Exemple #24
0
        public ActionResult AddItem(AdminPageModel PostedPage)
        {
            var CategoriesList = _categoryService.GetSelectedCategory(PostedPage.taggles);

            var Item = new ItemModel()
            {
                Number      = PostedPage.NewItem.Number,
                Name        = PostedPage.NewItem.Name,
                Price       = PostedPage.NewItem.Price,
                Description = PostedPage.NewItem.Description
            };

            _itemService.Add(Item, CategoriesList);

            return(RedirectToAction("Index", "Article"));
        }
        public ActionResult Demo(ItemServiceModel model)
        {
            var item = new ItemServiceModel
            {
                Name           = "Milk",
                Price          = 15,
                DateOfPurchase = DateTime.UtcNow,
                ItemType       = (Omack.Core.Enums.ItemType) 1,
                UserId         = 2,
                GroupId        = 10,
                MediaId        = 1
            };

            _itemService.Add(item, _siteUtils.CurrentUser.Id, _siteUtils.CurrentGroup.Id);
            return(Ok(item));
        }
Exemple #26
0
        public async Task <ActionResult> Add([FromBody] AddItemModel addItemModel)
        {
            if (ModelState.IsValid)
            {
                var itemDto = new ItemDto
                {
                    Name         = addItemModel.Name,
                    ParentItemId = addItemModel.ParentItemId
                };

                await _itemService.Add(itemDto, GetUserId());

                return(Ok());
            }

            return(BadRequest());
        }
Exemple #27
0
        public async Task Should_add_an_item()
        {
            //Act
            var itemResponse = await _itemService.Add(_itemRequest);

            //Assert
            itemResponse.Id.Should().BeEmpty();
            itemResponse.Description.Should().Be(_itemRequest.Description);
            itemResponse.Price.Should().Be(_itemRequest.Price);
            itemResponse.Active.Should().BeTrue();

            await _itemRepository.Received(1).Add(Arg.Is <Item>(i =>
                                                                i.Description == _itemRequest.Description &&
                                                                i.Price == _itemRequest.Price &&
                                                                i.Active
                                                                ));
        }
Exemple #28
0
        public void Post([FromBody] ItemDto value)
        {
            var i = new Item();

            i.Name    = value.Name;
            i.Enabled = true;

            if (value.Floor != null)
            {
                i.Floor = new Floor
                {
                    Number   = value.Floor.Number,
                    Building = value.Floor?.Building,
                };
            }

            _itemService.Add(i);
        }
Exemple #29
0
        private void DoSave()
        {
            if (!ValidateItem())
            {
                return;
            }

            var collectedItem = new Item {
                ItemName    = ItemName,
                Latitude    = Latitude,
                Longitude   = Longitude,
                ItemCreated = DateTime.Now,
                Description = Description,
                ImagePath   = _imageStore.SaveImageToFile(PictureBytes)
            };

            _itemService.Add(collectedItem);
            Close(this);
        }
        public IHttpActionResult create([FromBody] ItemDTO itemDTO)
        {
            Item item = new Item
            {
                Title       = itemDTO.Title,
                Description = itemDTO.Description,
                DueDate     = itemDTO.DueDate,
                PriorityId  = itemDTO.PriorityId
            };
            int id = _ItemService.Add(item);

            if (id <= 0)
            {
                return(BadRequest("Unable To Create Item"));
            }
            var payload = new { ItemId = id };

            return(Ok(payload));
        }