Exemplo n.º 1
0
        public async Task <IActionResult> Index([FromForm] IndexCard indexcard)
        {
            IIndexCard lIndexCard = indexcard;

            // howto upload files: https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads?view=aspnetcore-3.1#upload-small-files-with-buffered-model-binding-to-physical-storage

            // check if user is owner of the index card
            if (IndexCardBox.UserIsOwnerOfIndexCardBox(indexcard.IndexCardBoxId, base.GetCurrentUser(_context), _context) == false)
            {
                return(Forbid());
            }

            // save uploaded files
            lIndexCard = await HandleUploadedFiles(lIndexCard);

            // set date
            lIndexCard.Created  = DateTime.UtcNow;
            lIndexCard.Modified = DateTime.UtcNow;

            // save in database
            _context.IndexCards.Add((IndexCard)lIndexCard);
            await _context.SaveChangesAsync();

            // cleanup the indexcard response object
            lIndexCard = CleanupIndexCardResponse(lIndexCard);

            // return created indexcard
            return(Json(lIndexCard));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Index(IndexCardBox indexCardBox)
        {
            var lIndexCardBox = indexCardBox;

            // ToDo: Validate data

            // add user id
            IUser lUser = base.GetCurrentUser(_context);

            lIndexCardBox.UserId = lUser.Id;

            // set date
            lIndexCardBox.Created  = DateTime.UtcNow;
            lIndexCardBox.Modified = DateTime.UtcNow;

            // add Owner
            lIndexCardBox.UserId = lUser.Id;

            // save in database
            _context.IndexCardBoxes.Add(lIndexCardBox);
            await _context.SaveChangesAsync();

            return(Json(lIndexCardBox));
        }