public IActionResult CreateItem([FromBody] ItemCreateModel item) { if (item == null || !ModelState.IsValid) { return(BadRequest(ModelState)); } var newItem = new ItemDataTransferObject { Name = item.Name, Code = item.Code, Price = item.Price, Category = item.Category }; var newItemId = _itemService.CreateItem(newItem); return(CreatedAtRoute("GetItem", new { id = newItemId }, new ItemGetModel { Id = newItemId, Name = newItem.Name, Code = newItem.Code, Price = newItem.Price, Category = newItem.Category })); }
public ActionResult Create(ItemCreateModel itemCM) { Item item = Mapper.Map <ItemCreateModel, Item>(itemCM); itemService.CreateItem(item); return(RedirectToAction("Index")); }
public ActionResult Create() { ItemCreateModel ItemCM = new ItemCreateModel(); ItemCM.CategoryList = GetSelectList(); return(View(ItemCM)); }
public ItemModel PostAddItem(ItemCreateModel itemCreateModel, [ValueProvider(typeof(HeaderValueProviderFactory <string>))] string sessionKey) { var responseMsg = this.PerformOperationAndHandleExceptions(() => { var user = GetAndValidateUser(sessionKey); Item item = new Item(); item.Title = itemCreateModel.Title; if (itemCreateModel.ParentId == 0 || itemCreateModel.ParentId == null) { var rootUserElementId = this.GetAll(sessionKey).SingleOrDefault(it => it.ParentId == null).Id; item.ParentId = rootUserElementId; } else { item.ParentId = itemCreateModel.ParentId; } item.ItemType = itemCreateModel.ItemType; item.UserId = user.Id; this.Data.Items.Add(item); this.Data.SaveChanges(); var itemModel = this.Data.Items.All().Select(ItemModel.FromItem).SingleOrDefault(it => it.Id == item.Id); return(itemModel); }); return(responseMsg); }
public async Task <OperationResult> CreateItem(ItemCreateModel createItemModel) { try { var item = new Item { Available = createItemModel.Available, CustomerId = createItemModel.CustomerId, CreatedByUserId = _userService.UserId, UpdatedByUserId = _userService.UserId, ExpirationDate = createItemModel.ExpirationDate, ItemTypeId = createItemModel.ItemTypeId, Location = createItemModel.Location, SN = createItemModel.SN, }; await item.Create(_dbContext); var option = _options.Value; if (option.InventoryFormId > 0 && option.FolderId > 0) { var theCore = await _coreService.GetCore(); await using var sdkDbContext = theCore.DbContextHelper.GetDbContext(); var folder = sdkDbContext.Folders.Single(x => x.Id == option.FolderId); if (item.Available) { foreach (var assignedSite in _dbContext.AssignedSites.Where(x => x.WorkflowState != Constants.WorkflowStates.Removed)) { var siteLanguageId = await sdkDbContext.Sites .Where(x => x.MicrotingUid == assignedSite.SiteUid) .Select(x => x.LanguageId) .SingleAsync(); var language = await sdkDbContext.Languages.SingleAsync(x => x.Id == siteLanguageId); var mainElement = await theCore.ReadeForm(option.InventoryFormId, language); mainElement.CheckListFolderName = folder.Name; mainElement.EndDate = DateTime.UtcNow.AddYears(10); mainElement.Repeated = 0; mainElement.PushMessageTitle = mainElement.Label; // ReSharper disable once PossibleInvalidOperationException await theCore.CaseCreate(mainElement, "", assignedSite.SiteUid, (int)folder.MicrotingUid); } } } return(new OperationResult(true, _inventoryLocalizationService.GetString("ItemCreatedSuccessfully"))); } catch (Exception e) { Trace.TraceError(e.Message); return(new OperationResult(false, _inventoryLocalizationService.GetString("ErrorWhileCreatingItem"))); } }
public ActionResult Create() { ViewBag.UserId = User.Identity.GetUserId(); var model = new ItemCreateModel(); model.Catalogue = ItemRepository.GetSelectCatalogue(); return(View(model)); }
private async Task Add(ItemCreateModel model) { var json = JsonConvert.SerializeObject(model); var content = new StringContent(json); content.Headers.Clear(); content.Headers.Add("Content-Type", new[] { "application/json" }); var response = await _client.PostAsync("/items/add", content); response.EnsureSuccessStatusCode(); }
public ItemViewModel SaveItemCreateModelToDb(ItemCreateModel createModel) { Item item = new Item() { Name = createModel.Name, Code = createModel.Code, Price = createModel.Price, Category = createModel.Category }; _unitOfWork.Items.Create(item); return(GetItemsDBToViewModelById(item.Id)); }
public async Task AdOneToAll() { var item = new ItemCreateModel { Name = "Test", Price = 0 }; var oldItems = await GetAll(); await Add(item); var newItems = await GetAll(); Assert.Equal(oldItems.Count + 1, newItems.Count); Assert.Contains(newItems, model => model.Name == item.Name); }
public async Task <OperationResult> CreateInventoryType([FromBody] ItemCreateModel itemCreateModel) { return(await _inventoryItemService.CreateItem(itemCreateModel)); }
public void Add([FromBody] ItemCreateModel model) { _service.Add(model.ToItem()); }
public IActionResult Create([FromBody] ItemCreateModel item) { return Ok(_itemServieces.SaveItemCreateModelToDb(item)); }