public async Task <int> Create(CreateItemDto createItemDto) { var item = CreateItemDtoToEntity(createItemDto); var createdItemId = await _repository.Add(item); return(createdItemId); }
public async Task <ItemDto> CreateAsync(CreateItemDto createItemDto) { var itemListEntity = await _tripFlipDbContext.ItemLists .AsNoTracking() .SingleOrDefaultAsync(itemList => createItemDto.ItemListId == itemList.Id); EntityValidationHelper .ValidateEntityNotNull(itemListEntity, ErrorConstants.ItemListNotFound); // Validate current user has route 'Admin' role. await EntityValidationHelper.ValidateCurrentUserRouteRoleAsync( currentUserService : _currentUserService, tripFlipDbContext : _tripFlipDbContext, routeId : itemListEntity.RouteId, routeRoleToValidate : RouteRoles.Admin, errorMessage : ErrorConstants.NotRouteAdmin); var itemEntity = _mapper.Map <ItemEntity>(createItemDto); await _tripFlipDbContext.Items.AddAsync(itemEntity); await _tripFlipDbContext.SaveChangesAsync(); var itemDto = _mapper.Map <ItemDto>(itemEntity); return(itemDto); }
public async Task <IActionResult> Add(ItemAddInputModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } var dto = new CreateItemDto() { Name = input.Name, Type = input.Type, Shape = input.Shape, Weight = input.Weight, Purity = input.Purity, Fineness = input.Fineness, Quantity = input.Quantity, Dimensions = input.Dimensions, Description = input.Description, ManufacturerId = input.ManufacturerId, }; var userId = await this.usersService.GetIdAsync(input.Username); await this.itemsService.CreateAsync(dto, userId, input.Files, Path.Combine(this.hostingEnvironment.WebRootPath, "images", "items")); return(this.RedirectToAction("Pending")); }
public async Task <ActionResult <Item> > CreateItemAsync(CreateItemDto itemDto) { var item = itemDto.AsItem(); await repository.CreateItemAsync(item); return(CreatedAtAction(nameof(GetItemAsync), new { id = item.Id }, item)); }
public static Item AsItem(this CreateItemDto itemDto) { return(new Item { Id = Guid.NewGuid(), Name = itemDto.Name, Price = itemDto.Price, CreatedDate = DateTimeOffset.UtcNow }); }
private Item CreateItemDtoToEntity(CreateItemDto itemDto) { return(new Item { Name = itemDto.Name, Description = itemDto.Description, Value = itemDto.Value.Value, Count = itemDto.Count.Value }); }
public ActionResult <ItemDto> CreateItem(CreateItemDto itemDto) { Item item = new(){ Id = Guid.NewGuid(), Name = itemDto.Name, Price = itemDto.Price, CreatedDate = DateTimeOffset.UtcNow }; repository.CrateItem(item); return(CreatedAtAction(nameof(GetItems), new{ id = item.Id }, item.ASDto())); }
public ActionResult <ItemDto> CreateItem(CreateItemDto itemDto) { Item item = new() { Id = Guid.NewGuid(), Name = itemDto.Name, CPF = itemDto.CPF }; repository.CreateItem(item); return(CreatedAtAction(nameof(GetItem), new{ id = item.Id }, item.AsDto())); }
public async Task <IActionResult> Post([FromBody] CreateItemDto createItemDto) { using (TransactionScope ts = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { var itemId = await _itemService.Create(createItemDto); await _tableService.AddStateTracking <Item>(itemId); ts.Complete(); } return(Ok()); }
public async Task CreateAsync(CreateItemDto dto, string userId, IFormFileCollection images, string imagesFolder) { var item = this.itemsRepository.All().SingleOrDefault(x => x.Name == dto.Name); if (item != null) { throw new Exception($"Item {dto.Name} already exists."); } item = new Item() { Name = dto.Name, Type = (ItemType)Enum.ToObject(typeof(ItemType), dto.Type), Shape = (ItemShape)Enum.ToObject(typeof(ItemShape), dto.Shape), Weight = dto.Weight, Purity = dto.Purity, Fineness = (Carats)Enum.ToObject(typeof(Carats), dto.Fineness), Price = this.CalculateItemPrice(), // implement!!! Quantity = dto.Quantity, Dimensions = dto.Dimensions, Description = dto.Description, ManufacturerId = dto.ManufacturerId, }; foreach (var inputImage in images) { var image = this.imagesRepository.All().SingleOrDefault(x => x.Name == inputImage.FileName); if (image != null) { throw new Exception($"You cannot impload {inputImage} twice."); } else if (!Regex.IsMatch(inputImage.FileName, this.pattern)) { throw new Exception($"Invalid image extention {Path.GetExtension(inputImage.FileName)}"); } image = new Image { AddedByEmployeeId = userId, Name = inputImage.FileName, Extension = this.ChangeToContentType(Path.GetExtension(inputImage.FileName).Replace(".", string.Empty).Trim()), }; item.Images.Add(image); } await this.UploadImagesToDirectory(imagesFolder, images); await this.itemsRepository.AddAsync(item); await this.itemsRepository.SaveChangesAsync(); }
public async Task <ActionResult <ItemDto> > CreateItemAsync(CreateItemDto itemDto) { Item item = new(){ Id = Guid.NewGuid(), Name = itemDto.Name, Price = itemDto.Price, CreatedDate = DateTimeOffset.UtcNow }; await repository.CreateItemAsync(item); return(CreatedAtAction(nameof(GetItemAsync), new { id = item.Id }, item.AsDTO())); }
public async Task <ActionResult <ItemDto> > CreateItem(CreateItemDto itemDto) { Item itemToInsert = new(){ Id = Guid.NewGuid(), Name = itemDto.Name, Price = itemDto.Price, CreatedDate = DateTimeOffset.UtcNow }; var item = await this.itemsRepository.CreateAsync(itemToInsert); return(CreatedAtAction(nameof(GetItem), new { id = item.Id }, new ItemDto(item))); }
public ActionResult <ItemDto> createItem(CreateItemDto i) { Item item = new() { id = Guid.NewGuid(), name = i.name, price = i.price, createdOn = DateTimeOffset.UtcNow }; itemRepostory.createItem(item); return(CreatedAtAction(nameof(findOne), new { id = item.id }, item.asDto())); }
public ActionResult <ItemDto> CreatedItems(CreateItemDto items) { mlItems item = new() { Code = Guid.NewGuid(), Name = items.Name, Price = items.Price, CreatedDate = DateTimeOffset.Now }; repository.CreateItems(item); return(CreatedAtAction(nameof(GetItems), new { Code = item.Code }, item.AsDtos())); }
public async Task <ActionResult <ItemDto> > PostAsync(CreateItemDto createItemDto) { var item = new Item { Name = createItemDto.Name, Description = createItemDto.Description, Price = createItemDto.Price, CreatedDate = DateTimeOffset.Now }; await _itemsRepository.CreateAsync(item); return(CreatedAtAction("GetById", "Items", new { id = item.Id }, item)); }
[HttpPost] //post/items public async Task <ActionResult <ItemDto> > CreateItemAsync(CreateItemDto itemDto) { Item item = new() { Id = Guid.NewGuid(), Name = itemDto.Name, Price = itemDto.Price, CreateDate = DateTimeOffset.UtcNow }; await repository.CreateItemAsync(item); return(CreatedAtAction(nameof(GetItemAsync), new{ id = item.Id }, item.AsDto())); //created at returns 201 response , gets name of item and id, and return ItemDto }
/// <summary> /// /// </summary> /// <param name="input"></param> /// <returns></returns> public AxisItemDto CreateItem(CreateItemDto input) { var entity = Mapper.Map <TimeAxisItem>(input); var line = _axisRepository.Get(input.AxisId); if (!_authorityManager.HasAuthority(AbpSession.GetUserId(), line, AuthorityType.AddItem)) { Throw403Error(); } line.AddItem(entity); UnitOfWorkManager.Current.SaveChanges(); return(Mapper.Map <AxisItemDto>(entity)); }
public async Task <ActionResult <ItemDto> > CreateItemAsync(CreateItemDto itemDto) { Item item = new() { Id = Guid.NewGuid(), Name = itemDto.Name, Price = itemDto.Price, CreateDate = DateTimeOffset.UtcNow }; await _repository.CreateItemAsync(item); // ReSharper disable once Mvc.ActionNotResolved return(CreatedAtAction(nameof(GetItemAsync), new { id = item.Id }, item.AsDto())); }
public async Task <ActionResult <ItemDto> > PostAsync(CreateItemDto createItemDto) { var item = new Item { Name = createItemDto.Name, Description = createItemDto.Description, Price = createItemDto.Price, CreatedDate = DateTimeOffset.UtcNow }; await itemsRepository.CreateAsync(item); await publishEndpoint.Publish(new CatalogItemCreated(item.Id, item.Name, item.Description)); return(CreatedAtAction(nameof(GetByIdAsync), new { id = item.Id }, item)); }
public async Task <IActionResult> CreateItem([FromBody] CreateItemDto createItemDto) { CreateItemCommand command = new CreateItemCommand() { Name = createItemDto.Name, Description = createItemDto.Description, ItemTypeId = createItemDto.ItemTypeId, PurchaseDate = createItemDto.PurchaseDate, PurchasePrice = createItemDto.PurchasePrice, ExpirationDate = createItemDto.ExpirationDate, LastUsed = createItemDto.LastUsed }; await Mediator.Send(command); return(Ok()); }
public async Task <ActionResult <ItemResponseDto> > Create([FromBody] CreateItemDto itemDto) { var item = _mapper.Map <Item>(itemDto); item.CreatedDate = DateTimeOffset.UtcNow; bool created = await _itemsRepository.CreateAsync(item); if (!created) { return(BadRequest()); } await _publishEndpoint.Publish(new CatalogItemCreated(item.Id, item.Name, item.Description)); return(CreatedAtAction(nameof(Get), new { id = item.Id }, item)); }
public async Task <ActionResult> UpdateItemAsync(Guid id, CreateItemDto itemDto) { var existingItem = await repository.GetItemAsync(id); if (existingItem is null) { return(NotFound()); } Item updatedItem = existingItem with { Name = itemDto.Name, Price = itemDto.Price }; await repository.UpdateItemAsync(updatedItem); return(NoContent()); }
public async Task <ActionResult <ItemDto> > CreateBinType(CreateItemDto createItemDto) { var item = new Item { ItemNumber = createItemDto.ItemNumber, ItemDescription = createItemDto.ItemDescription, ItemPrice = createItemDto.ItemPrice, UpcCode = createItemDto.UpcCode, ItemStatus = createItemDto.ItemStatus, UnitOfMeasure = createItemDto.UnitOfMeasure, UomUnit = createItemDto.UomUnit, FDA = createItemDto.FDA }; _itemRepository.AddItem(item); if (await _itemRepository.SaveAllAsync()) { return(Ok(_mapper.Map <ItemDto>(item))); } return(BadRequest("Failed to add item.")); }
public async Task <IActionResult> Create([FromForm] CreateItemDto item) { Item newItem = new Item() { Description = item.Description, Discount = item.Discount, MadeAt = item.MadeAt, Name = item.Name, Price = item.Price }; newItem.Tags = new List <Tag>(); foreach (var tagId in item.TagIds) { newItem.Tags.Add(_context.Tags.FirstOrDefault(x => x.Id == tagId)); } _context.Items.Add(newItem); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <ActionResult <Item> > PostItem(CreateItemDto item) { Item newItem = new Item() { Description = item.Description, Discount = item.Discount, MadeAt = item.MadeAt, Name = item.Name, Price = item.Price }; newItem.Tags = new List <Tag>(); foreach (var tagId in item.TagIds) { newItem.Tags.Add(_context.Tags.FirstOrDefault(x => x.Id == tagId)); } _context.Items.Add(newItem); await _context.SaveChangesAsync(); return(CreatedAtAction("GetItem", new { id = newItem.Id }, newItem)); }