Esempio n. 1
0
        public async Task <IActionResult> AddItem(Item newItem)
        {
            var currentUser = await _userManager.GetUserAsync(User);

            if (currentUser == null)
            {
                return(Challenge());
            }

            if (!ModelState.IsValid)
            {
                return(View(newItem));
            }

            newItem.Id = Guid.NewGuid();
            var successfull = await _itemService.AddItemAsync(newItem, currentUser);

            if (!successfull)
            {
                return(BadRequest("Could not add item."));
            }
            else
            {
                var photos = HttpContext.Request.Form.Files;

                foreach (var Image in photos)
                {
                    if (Image != null && Image.Length > 0)
                    {
                        var file       = Image;
                        int nameFolder = 1;
                        var uploads    = Path.Combine(_hostEnvironment.WebRootPath, "uploads\\itemImages\\" + nameFolder);
                        int countFiles = Directory.GetFiles(uploads, "*", SearchOption.TopDirectoryOnly).Length;

                        while (countFiles > 254)
                        {
                            uploads = Path.Combine(_hostEnvironment.WebRootPath, "uploads\\itemImages\\" + (++nameFolder));
                        }

                        if (file.Length > 0)
                        {
                            var fileName = newItem.Id + ".jpg";
                            using (var fileStream = new FileStream(Path.Combine(uploads, fileName), FileMode.Create))
                            {
                                await file.CopyToAsync(fileStream);

                                newItem.Photo = nameFolder;
                                await _itemService.UpdateItem(newItem);
                            }
                        }
                    }
                }
            }

            return(RedirectToAction("Index"));
        }
Esempio n. 2
0
        public async Task <IActionResult> AddItem([FromRoute] string projectKey, [FromBody] UpsertItemParams ps)
        {
            if (!await _permissionService.HasProjectPermissionAsync(projectKey, Permission.Admin))
            {
                return(StatusCode(403, "You have no permission to add item."));
            }

            ps.ProjectKey = projectKey;
            return(Ok(await _itemService.AddItemAsync(ps)));
        }
        public async Task <IActionResult> AddItem([FromBody] CreateItemRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Select(x => x.Value.Errors)
                                  .Where(x => x.Count > 0)
                                  .ToList()));
            }

            var addedItem = await _itemService.AddItemAsync(request);

            return(new OkObjectResult(addedItem));
        }
        public async Task <IActionResult> AddItem(
            AddItemDto model
            )
        {
            try
            {
                var responsePayload = await _itemService.AddItemAsync(model);

                return(Ok(responsePayload));
            }
            catch (Exception ex)
            {
                return(BadRequest(new { ex.Message }));
            }
        }
Esempio n. 5
0
        public async Task <IActionResult> AddMeetingItem(ItemViewModel meetingItemViewViewModel)
        {
            var item = await _itemService.AddItemAsync(new ItemEntity
            {
                Description = meetingItemViewViewModel.Description,
                UserId      = meetingItemViewViewModel.UserId,
                DueDate     = meetingItemViewViewModel.DueDate,
                Meeting     = new MeetingEntity
                {
                    Id = meetingItemViewViewModel.Meeting.Id
                }
            });

            return(RedirectToAction("Index", new RouteValueDictionary(new { controller = "MeetingItem", action = "Index", Id = item.Meeting.Id })));
        }
Esempio n. 6
0
        public async Task AddItem(CommandContext ctx, string itemName, string itemDescription)
        {
            var user = new DiscordUserModel {
                UserId = ctx.Member.Id, DisplayName = ctx.Member.DisplayName
            };
            var loggingEvent = new LoggingEventModel
            {
                Date = DateTime.UtcNow,
                DiscordDisplayName = user.DisplayName,
                DiscordUserId      = user.UserId,
                LoggingType        = LoggingTypeEnum.Command,
                Message            = "AddItem"
            };
            await _loggingService.AddLoggingMessage(loggingEvent);

            await _itemService.AddItemAsync(itemName, itemDescription);

            await ctx.Channel.SendMessageAsync("Item added").ConfigureAwait(false);
        }
        public async Task <IActionResult> Post(AddItemRequest request)
        {
            var result = await _itemService.AddItemAsync(request);

            return(CreatedAtAction(nameof(GetById), new { id = result.Id }, null));
        }
Esempio n. 8
0
 public async Task <ActionResult <Item> > Post(Item itemmodele)
 {
     return(Ok(await _IItemService.AddItemAsync(itemmodele)));
 }