Esempio n. 1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var userId = User.Claims.Single(c => c.Type == UserHelper.NameIdentifierString).Value;

            Car.ClientUserId = userId;

            await FileHelpers.UploadAsync("C:/Users/csmar/source/repos/CarService/CarService.Web/wwwroot/pictures/", FileUpload);

            Car.Picture         = FileUpload.FileName;
            Car.PictureSize     = FileUpload.Length;
            Car.PictureUploadDT = DateTime.UtcNow;

            _context.Cars.Add(Car);

            _context.Attach(Car).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CarExists(Car.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./BrowseCar"));
        }
        public static async Task ModifyWorkAsync(Work work)
        {
            _context.Attach(work).State = EntityState.Modified;

            await _context.SaveChangesAsync();
        }