示例#1
0
        private async Task <ActionResult <Auction> > ChangeAuctionStatus(int id, AuctionStatus status)
        {
            var auction = await _context.Auction
                          .Where(x => x.ID == id)
                          .FirstOrDefaultAsync();

            if (auction == null)
            {
                return(NotFound());
            }

            auction.Status = status;
            _context.Entry(auction).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AuctionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(auction);
        }
示例#2
0
        public async Task <IActionResult> UploadImageLot([FromForm] List <IFormFile> files, int id)
        {
            long size = files.Sum(f => f.Length);

            foreach (var file in files)
            {
                if (file.Length > 0)
                {
                    var path = Path.GetTempFileName();

                    LotImage lastImage = null;

                    if (_context.LotImage.Count() > 0)
                    {
                        lastImage = await _context.LotImage
                                    .OrderBy(x => x.ID)
                                    .LastAsync();
                    }

                    int lastImageID = 1;
                    if (lastImage != null)
                    {
                        lastImageID = (lastImage.ID + 1);
                    }

                    using (var stream = System.IO.File.Create(path))
                    {
                        await file.CopyToAsync(stream);
                    }

                    var newpath = VeilingConfiguration.LotImageLocation + $"/{id}/{lastImageID}{FileContentType.GetExtension(file.ContentType)}";
                    Directory.CreateDirectory(Path.GetDirectoryName(newpath));
                    System.IO.File.Delete(newpath);

                    _context.LotImage.Add(new LotImage()
                    {
                        LotID = id, ImageLocation = newpath, ID = lastImageID, AspectRatio = LotImage.CalculateAspectRatio(file.OpenReadStream())
                    });
                    await _context.SaveChangesAsync();

                    System.IO.File.Move(path, newpath);
                    System.IO.File.Delete(path);
                }
            }

            return(Ok(new { count = files.Count, size }));
        }
示例#3
0
        public async Task <ActionResult <PostMessage> > RegisterUser([FromForm] string email, [FromForm] string hashedpassword)
        {
            if (string.IsNullOrEmpty(email))
            {
                return(new PostMessage("The email is empty."));
            }

            if (string.IsNullOrEmpty(hashedpassword))
            {
                return(new PostMessage("No password was defined."));
            }

            if (!email.Contains("@") || email.Length < 10)
            {
                return(new PostMessage("Invalid email."));
            }

            var user = await _context.Users.Where(x => x.Email.Trim() == email.Trim())
                       .AsNoTracking()
                       .FirstOrDefaultAsync();

            if (user != null)
            {
                return(new PostMessage("There already exists a user with that email."));
            }

            int lastUserId = 1;
            int lastApiId  = 1;
            int lastRoleId = 1;

            var lastUser = await _context.Users.OrderByDescending(x => x.ID).FirstOrDefaultAsync();

            if (lastUser != null)
            {
                lastUserId = lastUser.ID + 1;
            }

            var lastApi = await _context.ApiKey.OrderByDescending(x => x.ID).FirstOrDefaultAsync();

            if (lastApi != null)
            {
                lastApiId = lastApi.ID + 1;
            }

            var lastRole = await _context.Role.OrderByDescending(x => x.ID).FirstOrDefaultAsync();

            if (lastRole != null)
            {
                lastRoleId = lastRole.ID + 1;
            }

            var newUser = new User(lastUserId, email, hashedpassword, lastApiId, lastRoleId);

            _context.Users.Add(newUser);
            await _context.SaveChangesAsync();

            return(new PostMessage());
        }