//[Authorize(Roles = "Administrator")]
        public async Task <IActionResult> Edit(int id, [Bind("Id,DisplayName,FirstName,LastName,Age,Gender,Bio,UserAccountId")]
                                               DatingProfile datingProfile, IFormFile FilePhoto)
        {
            if (id != datingProfile.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(datingProfile);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DatingProfileExists(datingProfile.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(datingProfile));
        }
示例#2
0
        public IActionResult Read(int id)
        {
            MailMessage mail = _context.MailMessage.FirstOrDefault(m => m.Id == id);

            mail.IsRead = true;
            _context.Update(mail);
            _context.SaveChanges();
            return(View(mail));
        }
示例#3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,FirstName,LastName,DisplayName,Age,Gender,Bio,UserAccountId")] DatingProfile datingProfile,
                                               IFormFile FilePhoto)
        {
            if (id != datingProfile.Id)
            {
                return(NotFound());
            }

            if (FilePhoto.Length > 0)
            {
                string photoPath = _webroot.WebRootPath + "\\userPhotos\\";
                var    fileName  = Path.GetFileName(FilePhoto.FileName);

                using (var stream = System.IO.File.Create(photoPath + fileName))
                {
                    await FilePhoto.CopyToAsync(stream);

                    datingProfile.PhotoPath = fileName;
                }
            }


            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(datingProfile);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DatingProfileExists(datingProfile.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(datingProfile));
        }