public async Task <IActionResult> Create([Bind("Brand,Model,Code,ItemTypeId,ColorId,Price,Quantity")] ItemCreateBindingModel item)
        {
            if (ModelState.IsValid)
            {
                //var currentItem = new Item()
                //{
                //    Brand = item.Brand,
                //    Model = item.Model,
                //    Code = item.Code,
                //    ItemTypeId = item.ItemTypeId,
                //    ColorId = item.ColorId,
                //    Quantity = item.Quantity,
                //    Price = item.Price
                //};

                var currentItem = mapper.Map <Item>(item);

                await service.CreateItemAsync(currentItem);

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ColorId"]    = new SelectList(service.GetAllItemColorsAsync().Result, "Id", "Name", item.ColorId);
            ViewData["ItemTypeId"] = new SelectList(service.GetAllItemTypesAsync().Result, "Id", "Name", item.ItemTypeId);
            return(View(item));
        }
        public async Task <IActionResult> Post([FromBody] ToDoItemRequest model)
        {
            if (ModelState.IsValid)
            {
                var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;
                var plan   = await _itemsService.CreateItemAsync(model.PlanId, model.Description, model.EstimatedDate, userId);

                return(Ok(new OperationResponse <ToDoItem>
                {
                    IsSuccess = true,
                    Message = "Item has been inserted successfully",
                    Record = plan
                }));
            }

            return(BadRequest(new OperationResponse <ToDoItem>
            {
                IsSuccess = true,
                Message = "Some properties are not valid"
            }));
        }
Exemple #3
0
        public async Task <IActionResult> Post(ToDoItemDetail item)
        {
            var result = await _itemsService.CreateItemAsync(item, UserId);

            return(Ok(result.Content));
        }