コード例 #1
0
        public async Task DeleteUserByIdAsync(string Id)
        {
            var user = await _dbContext.Users.FindAsync(Id);

            _dbContext.Entry(user).Reference(c => c.UserProfile).Load();
            _dbContext.Users.Remove(user);
        }
コード例 #2
0
        public async Task <IActionResult> PutTopic(int id, Topic topic)
        {
            if (id != topic.Id)
            {
                return(BadRequest());
            }

            _context.Entry(topic).State = EntityState.Modified;

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

            return(NoContent());
        }
コード例 #3
0
        public static void Main()
        {
            using (var context = new ForumDbContext())
            {
                /* Test RegistrationDate - Shadow Property */
                //Random random = new Random();

                //var users = context.Users.ToList();

                //foreach (var user in users)
                //{
                //    var seconds = random.Next(-100_000_000, -1);
                //    var randomDate = DateTime.Now.AddSeconds(seconds);

                //    context.Entry(user).Property("RegistrationDate").CurrentValue = randomDate;
                //}
                //context.SaveChanges();

                /* Order Posts by Shadow Property */
                var orderedUsers = context.Users
                                   .OrderBy(user => EF.Property <DateTime>(user, "RegistrationDate"))
                                   .ToList();

                foreach (var user in orderedUsers)
                {
                    Console.WriteLine(context.Entry(user).Property("RegistrationDate").CurrentValue);
                }

                /* Test LastUpdate - Shadow Property */
                //var post = context.Posts.Find(1);
                //post.Title = "Core za Facebook!";
                //context.SaveChanges();
            }
        }
コード例 #4
0
 public ActionResult Edit([Bind(Include = "Id,Title,Date,Category")] Thread thread)
 {
     if (ModelState.IsValid)
     {
         db.Entry(thread).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(thread));
 }
コード例 #5
0
 public ActionResult Edit([Bind(Include = "CategoryId,CategoryName,CategoryDescription")] Category category)
 {
     if (ModelState.IsValid)
     {
         db.Entry(category).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(category));
 }
コード例 #6
0
 public ActionResult Edit([Bind(Include = "Id,Body,Date")] Post post)
 {
     if (ModelState.IsValid)
     {
         db.Entry(post).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(post));
 }
コード例 #7
0
 public ActionResult Edit([Bind(Include = "Id,Category")] Forums forums)
 {
     if (ModelState.IsValid)
     {
         db.Entry(forums).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(forums));
 }
コード例 #8
0
 public ActionResult Edit([Bind(Include = "CategoryId,Name,Description,ParentId")] Category category)
 {
     if (ModelState.IsValid)
     {
         db.Entry(category).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ParentId = new SelectList(db.Categories, "CategoryId", "Name", category.ParentId);
     return(View(category));
 }
コード例 #9
0
 public ActionResult Edit([Bind(Include = "MessageId,SenderId,ReceiverId,Text,SendDate,Seen")] Message message)
 {
     if (ModelState.IsValid)
     {
         db.Entry(message).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ReceiverId = new SelectList(db.Users, "Id", "UserName", message.ReceiverId);
     ViewBag.SenderId   = new SelectList(db.Users, "Id", "UserName", message.SenderId);
     return(View(message));
 }
コード例 #10
0
 public ActionResult Edit([Bind(Include = "PostId,Body,AuthorId,CreatedTime,ThreadId")] Post post)
 {
     if (ModelState.IsValid)
     {
         db.Entry(post).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AuthorId = new SelectList(db.Users, "Id", "UserName", post.AuthorId);
     ViewBag.ThreadId = new SelectList(db.Threads, "ThreadId", "ThreadTitle", post.ThreadId);
     return(View(post));
 }
コード例 #11
0
 public ActionResult Edit([Bind(Include = "ThreadId,ThreadTitle,IsPinned,AuthorId,CategoryId")] Thread thread)
 {
     if (ModelState.IsValid)
     {
         db.Entry(thread).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AuthorId   = new SelectList(db.Users, "Id", "UserName", thread.AuthorId);
     ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "Name", thread.CategoryId);
     return(View(thread));
 }
コード例 #12
0
        public async Task <ActionResult <ProfileFull> > UpdateProfile([FromBody] ProfileUpdateForm _userData)
        {
            string UserName = this.User.Claims.First(i => i.Type == "UserName").Value;

            var user = await _context.User.FirstOrDefaultAsync(u => u.UserName == UserName);

            if (user == null)
            {
                return(BadRequest());
            }

            var UserAnswerResponse = new UserAnswer();

            UserAnswerResponse.profilefull = new ProfileFull(user);

            user.Name        = _userData.name;
            user.Surname     = _userData.surname;
            user.Birthdate   = _userData.birthdate;
            user.DisplayName = _userData.displayname;

            _context.Entry(user).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(user.UserName))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(UserAnswerResponse));
        }
コード例 #13
0
 public ActionResult Editar(Postagem post)
 {
     if (AutenticarUsuario.VerificarSessaoUsuario())
     {
         if (ModelState.IsValid)
         {
             db.Entry(post).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Index", new { idDoTopico = post.IdDoTopico }));
         }
         return(View(post));
     }
     return(Redirect("/Login"));
 }
コード例 #14
0
 public ActionResult Editar([Bind(Include = "ID,Nome,Login,Senha,PerfilDoUsuario")] Usuario usuario)
 {
     if (AutenticarUsuario.VerificarSessaoUsuario() && AutenticarUsuario.VerificarSessaoUsuario())
     {
         if (ModelState.IsValid)
         {
             db.Entry(usuario).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         return(View(usuario));
     }
     return(Redirect("/Login"));
 }
コード例 #15
0
        public ActionResult Edit(User user, String role)
        {
            if (ModelState.IsValid)
            {
                // Stamp so the identity doesn't crash
                user.SecurityStamp = Guid.NewGuid().ToString();

                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();

                // Delete all roles from user and add new one
                userManager.GetRoles(user.Id).ForEach(e => userManager.RemoveFromRole(user.Id, e));
                userManager.AddToRole(user.Id, role);
                return(RedirectToAction("Index"));
            }
            return(View(user));
        }
コード例 #16
0
 public void Update(User entity)
 {
     db.Entry(entity).State = EntityState.Modified;
 }
コード例 #17
0
ファイル: MessageRepository.cs プロジェクト: art3mm/ForumApp
 public void Update(Message entity)
 {
     _dbContext.Entry(entity).State = EntityState.Modified;
 }
コード例 #18
0
 public void Update(Topic entity)
 {
     _dbContext.Entry(entity).State = EntityState.Modified;
 }
コード例 #19
0
 public virtual void Update(T entity)
 {
     _dbContext.Entry(entity).State = EntityState.Modified;
 }
コード例 #20
0
 public void Update(Profile item)
 {
     context.Entry(item).State = EntityState.Modified;
     context.SaveChanges();
 }
コード例 #21
0
 public void Update(T obj)
 {
     table.Attach(obj);
     _context.Entry(obj).State = EntityState.Modified;
 }
コード例 #22
0
 public void Update(Complaint entity)
 {
     db.Entry(entity).State = EntityState.Modified;
 }
コード例 #23
0
ファイル: TopicRepository.cs プロジェクト: IvanBondarau/Forum
 public void Update(Topic item)
 {
     context.Entry(item).State = EntityState.Modified;
 }
コード例 #24
0
 public void Update(Message entity)
 {
     db.Entry(entity).State = EntityState.Modified;
 }