public virtual void Delete(TEntity entityToDelete)
 {
     if (Context.Entry(entityToDelete).State == EntityState.Detached)
     {
         DbSet.Attach(entityToDelete);
     }
     DbSet.Remove(entityToDelete);
 }
Esempio n. 2
0
        public async Task <ActionResult> ChangeProfilePicAsync(ChangeProfileViewModel model)
        {
            TARUser currentUser = UserManager.FindById(User.Identity.GetUserId());

            if (ModelState.IsValid)
            {
                if (model.ImageFile == null)
                {
                    model.ImagePath = currentUser.ImagePath;
                }
                else
                {
                    string fileName  = Path.GetFileNameWithoutExtension(model.ImageFile.FileName);
                    string extension = Path.GetExtension(model.ImageFile.FileName);
                    fileName        = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                    model.ImagePath = "~/Content/Images/" + fileName;
                    fileName        = Path.Combine(Server.MapPath("~/Content/Images/"), fileName);
                    model.ImageFile.SaveAs(fileName);
                }

                currentUser.ImagePath   = model.ImagePath;
                currentUser.DisplayName = model.Name;

                var manager = new UserManager <TARUser>
                                  (new UserStore <TARUser>
                                      (new TARDBContext()));

                context.Entry(currentUser).State = System.Data.Entity.EntityState.Modified;
                await context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("Index"));
        }
        public async System.Threading.Tasks.Task <ActionResult> AddMember(String email)
        {
            int teamId  = Convert.ToInt32(Session["teamIdForMember"]);
            int eventId = Convert.ToInt32(Session["eventIdForMember"]);

            //String email = tarUserViewModel.Email;

            List <Member> members = memberBAL.AddMembers(email, teamId, eventId);

            var UserManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();

            var user = await UserManager.FindByNameAsync(email);

            var userId = user.Id;

            TARUser currentUser = UserManager.FindById(userId);

            currentUser.isAssigned      = true;
            db.Entry(currentUser).State = System.Data.Entity.EntityState.Modified;
            await db.SaveChangesAsync();

            return(PartialView("_MemberList", members));
        }