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

            if (BugCreateVm.UploadedImage.Length > 0)
            {
                //TODO: Put this in a helper

                using (var ms = new MemoryStream())
                {
                    BugCreateVm.UploadedImage.CopyTo(ms);
                    //var fileBytes = ms.ToArray();
                    //string s = Convert.ToBase64String(fileBytes);
                    BugCreateVm.Image = ms.ToArray();
                }
            }

            var entry = _context.Add(new Bug());

            entry.CurrentValues.SetValues(BugCreateVm);

            //_context.Bugs.Add(BugVm);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            //TODO - Eventually add a check here to make sure the current user has access to this bug
            var bugToUpdate = await _context.Bugs.FindAsync(BugEditVm.BugID);

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

            if (BugEditVm.UploadedImage?.Length > 0)
            {
                //TODO: Put this in a helper

                using (var ms = new MemoryStream())
                {
                    BugEditVm.UploadedImage.CopyTo(ms);
                    BugEditVm.Image = ms.ToArray();
                }
            }

            MapVmToModel(bugToUpdate);

            //if (await TryUpdateModelAsync<Bug>(bugToUpdate, "", b => b.BugName, b => b.DateTimeReported, b => b.Description, b => b.Image))
            //{
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                //if (!BugExists(BugEditVm.BugID))
                //{
                //    return NotFound();
                //}
                //else
                //{
                throw;
                //}
            }
            //  }

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Bug = await _context.Bugs.FindAsync(id);

            if (Bug != null)
            {
                _context.Bugs.Remove(Bug);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }