当前位置: 首页>>代码示例>>C#>>正文


C# UserManager.FindById方法代码示例

本文整理汇总了C#中UserManager.FindById方法的典型用法代码示例。如果您正苦于以下问题:C# UserManager.FindById方法的具体用法?C# UserManager.FindById怎么用?C# UserManager.FindById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserManager的用法示例。


在下文中一共展示了UserManager.FindById方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddFollow

        public string AddFollow(string userId, string type)
        {
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db));
                var currentUser = manager.FindById(User.Identity.GetUserId());
                var followedUser = manager.FindById(userId);

                if (type.Equals("Follow"))
                {
                    currentUser.followList.Add(followedUser);
                }
                else
                {
                    UnFollow(currentUser, followedUser);
                }

                //manager.UpdateAsync(currentUser);

                var store = new UserStore<ApplicationUser>(new ApplicationDbContext());

                //store.Context.SaveChanges();
                db.SaveChanges();
                return "success";
            }
        }
开发者ID:yippee-ki-yay,项目名称:Codetweets,代码行数:26,代码来源:FeedController.cs

示例2: CreateFileUsingName

        public ContentResult CreateFileUsingName(string fileName)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(ctx));
                var currentUser = manager.FindById(User.Identity.GetUserId());
                var fileManager = new FileManager(manager.FindById(User.Identity.GetUserId()).Id);

                    var entity = new File
                    {
                        Nom = fileName,
                        DateCreation = DateTime.Now,
                        NombreObjets = 0,
                        Taille = 10,
                        User = currentUser
                    };
                    ctx.Files.Add(entity);
                    ctx.SaveChanges();

                    fileManager.Create(fileName, "Testing");

            }

            return Content("file Added");
        }
开发者ID:helmiderbali,项目名称:energySim,代码行数:25,代码来源:HomeController.cs

示例3: AddBlock

        public string AddBlock(string userId, string type)
        {
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db));
                var currentUser = manager.FindById(User.Identity.GetUserId());
                var blockedUser = manager.FindById(userId);

                if (type.Equals("Block"))
                {
                    currentUser.blockedList.Add(blockedUser);

                    //unfollow each person if there was any following
                    UnFollow(currentUser, blockedUser);
                    UnFollow(blockedUser, currentUser);
                }
                else  //unblock user just remove him from the list
                {
                    var block = currentUser.blockedList.Find(user => user.Id == blockedUser.Id);

                    if (block != null)
                    {
                        currentUser.blockedList.Remove(block);
                    }
                }

              //  manager.UpdateAsync(currentUser);

                var store = new UserStore<ApplicationUser>(new ApplicationDbContext());

               // store.Context.SaveChanges();
                db.SaveChanges();
                return "success";
            }
        }
开发者ID:yippee-ki-yay,项目名称:Codetweets,代码行数:35,代码来源:FeedController.cs

示例4: Create

        public ActionResult Create(PatientViewModel patientDetail)
        {
            var alreadyExists = db.PatientDetails.Where(p => p.FullName == patientDetail.PatientDetails.FullName && p.ContactNo == patientDetail.PatientDetails.ContactNo);
            if (alreadyExists.Count() > 0)
            {
                ModelState.AddModelError("", "Patient with same name and contact no already exists in the system");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var currentUserId = User.Identity.GetUserId();
                    long customerId = 1;
                    long branchId = 1;
                    if (currentUserId != null)
                    {
                        var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
                        customerId = manager.FindById(currentUserId).HMSEmpID;
                        branchId = manager.FindById(currentUserId).BranchID;
                        patientDetail.PatientDetails.CreatedBy = Convert.ToInt32(customerId);
                    }

                    DateTime today = DateTime.Today;
                    //int age = today.Year - patientDetail.PatientDetails.Age;
                    patientDetail.PatientDetails.DOB = today.AddYears(- (patientDetail.PatientDetails.Age));
                    //if (patientDetail.PatientDetails.DOB.Date > today.AddYears(-age)) age--;

                    //patientDetail.PatientDetails.Age = age;
                    patientDetail.PatientDetails.CreatedOn = DateTime.Now;
                    patientDetail.PatientDetails.DateOfRegistration = DateTime.Now;
                    db.PatientDetails.Add(patientDetail.PatientDetails);
                    db.SaveChanges();
                    patientDetail.Appointment.CreatedDate = DateTime.Now;
                    patientDetail.Appointment.CreatedBy = Convert.ToInt32(customerId);
                    //patientDetail.Appointment.BranchDetails_ID = Convert.ToInt32(branchId);
                    patientDetail.PatientDetails.Appointments.Add(patientDetail.Appointment);
                    db.SaveChanges();
                    return RedirectToAction("Index", "Appointments");
                }
                catch (Exception ex)
                {
                    throw ex;
                }

            }

            ViewBag.Specialization = new SelectList(db.Specializations.ToList(), "ID", "Name", patientDetail.Appointment.Specialization_ID);
            ViewBag.Doctors = new SelectList(db.Doctors.Include("EmployeeDetail").ToList(), "ID", "EmployeeDetail.FirstName", patientDetail.Appointment.Doctor_ID);
            ViewBag.City = new SelectList(db.Cities.ToList(), "ID", "Name", patientDetail.PatientDetails.City_ID);
            ViewBag.ShiftType = new SelectList(db.ShiftTypes, "ID", "Name", patientDetail.Appointment.ShiftType_ID);
            ViewBag.PatientType = new SelectList(db.PatientTypes, "ID", "Type", patientDetail.Appointment.PatientType_ID);
            ViewBag.Branch = new SelectList(db.BranchDetails, "ID", "Name", patientDetail.Appointment.BranchDetails_ID);
            return View(patientDetail);
        }
开发者ID:pramodprasad,项目名称:HMSApp,代码行数:55,代码来源:PatientController.cs

示例5: Certificate

        public ActionResult Certificate(int courseId)
        {
            string user = User.Identity.GetUserId();
            var u = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db));
            var course = db.Courses.First(c => c.id == courseId);
            string path;

            if (System.IO.File.Exists(Server.MapPath("~/resources/cert/" +  u.FindById(user).FirstName + "_" + u.FindById(user).LastName + "/" + course.name +".jpeg")))
            {
                path = "/resources/cert/" + u.FindById(user).FirstName + "_" + u.FindById(user).LastName + "/" + course.name + ".jpeg";
                ViewBag.Path = path;
                return View();
            }

            try
            {
                Image im = Image.FromFile(Server.MapPath("~/resources/cert/MyCertificate.jpeg"));
                path = PrintInPicture(im, u.FindById(user).FirstName, u.FindById(user).LastName, course.name);
            }
            catch (Exception)
            {
                Image im = Image.FromFile(Server.MapPath("~/resources/cert/MyCertificate.jpeg"));
                im.Save(Server.MapPath("~/resources/cert/MyCertificate1.jpeg"), System.Drawing.Imaging.ImageFormat.Jpeg);
                im = Image.FromFile(Server.MapPath("~/resources/cert/MyCertificate1.jpeg"));
                path = PrintInPicture(im, u.FindById(user).FirstName, u.FindById(user).LastName, course.name);
            }

            ViewBag.Path = path;
            return View();
        }
开发者ID:a01benson,项目名称:Course-Management-System,代码行数:30,代码来源:SubscribeController.cs

示例6: Index

        //
        // GET: /Manage/Index
        public async Task<ActionResult> Index(ManageMessageId? message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : "";

            var userId = User.Identity.GetUserId();
            var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
            var currentUser = manager.FindById(userId);

            var model = new IndexViewModel
            {
                HasPassword = HasPassword(),
                IoTConnectionString = currentUser.IoTHubConnectionString,
                IoTHubEndpoint = currentUser.IoTHubEndpoint,
                PhoneNumber = await UserManager.GetPhoneNumberAsync(userId),
                TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId),
                Logins = await UserManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId)
            };
            return View(model);
        }
开发者ID:ThingLabsIo,项目名称:ThingLabsWeb,代码行数:29,代码来源:ManageController.cs

示例7: AddImage

        public void AddImage()
        {
            if (System.Web.HttpContext.Current.Request.Files.AllKeys.Any())
            {
                var pic = System.Web.HttpContext.Current.Request.Files["HelpSectionImages"];

                string fileName = GenerateFileName("Image") +"."+ pic.FileName.Split('.')[1];

                pic.SaveAs(Server.MapPath("/img/" + fileName));

                using (ApplicationDbContext db = new ApplicationDbContext())
                {
                    var store = new UserStore<ApplicationUser>(db);
                    var manager = new UserManager<ApplicationUser>(store);
                    var currentUser = manager.FindById(User.Identity.GetUserId());

                    //if the user already has an image
                    if(currentUser.userImgPath != "")
                    {
                        reloadImage(currentUser, fileName);
                    }
                    else
                        currentUser.userImgPath = fileName;

                    db.SaveChanges();
                    // manager.UpdateAsync(currentUser);
                    //store.Context.SaveChanges();
                    // FormsAuthentication.SignOut();
                   // Session.Abandon();
                   // Index();
                }

            }
        }
开发者ID:yippee-ki-yay,项目名称:Codetweets,代码行数:34,代码来源:HomeController.cs

示例8: FileUpload

        public ActionResult FileUpload(HttpPostedFileBase file)
        {
            if (file != null)
            {
                using (var dbContext = new YATContext())
                {
                    var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
                    var currentUser = manager.FindById(User.Identity.GetUserId());
                    var YATUser = dbContext.User.Where(p => p.Id.Equals(currentUser.Id)).FirstOrDefault();

                    string picName = System.IO.Path.GetFileName(file.FileName);
                    String photo = YATUser.Id + Path.GetExtension(picName);
                    file.SaveAs(Server.MapPath("~/Pics/" + photo));

                    YATUser.Photo = photo;
                    dbContext.SaveChanges();
                }

                using (MemoryStream ms = new MemoryStream())
                {
                    file.InputStream.CopyTo(ms);
                    byte[] array = ms.GetBuffer();
                }

            }
            return RedirectToAction("UserSettings", "UserProfile");
        }
开发者ID:contactaditya,项目名称:.NET-Web-Application-Project,代码行数:27,代码来源:UserProfileController.cs

示例9: Create

        public ActionResult Create([Bind(Include = "Id,StartTime,EndTime,DepartmentId,GroupId")] Schedule schedule)
        {
            var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db));
            var currentUser = userManager.FindById(User.Identity.GetUserId());

            if (ModelState.IsValid && User.Identity.IsAuthenticated)
            {
                if (schedule.DepartmentId == 0 && schedule.GroupId == null)
                {
                    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                }
                Department department = db.Departments.Find(schedule.DepartmentId) ?? db.DepartmentGroups.Find(schedule.GroupId).Department;
                if (department == null)
                {
                    return HttpNotFound();
                }
                if (department.Bosses.Contains(currentUser)) //Current logged in user must be boss for the department
                {
                    db.Schedules.Add(schedule);
                    db.SaveChanges();

                    return RedirectToAction("Index", "Schedules", new { departmentId = schedule.DepartmentId, groupId = schedule.GroupId });
                }
                else
                {
                    return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
                }
            }
            ViewBag.DepartmentId = new SelectList(db.Departments.ToList().Where(q => q.Bosses.Contains(currentUser)).ToList(), "Id", "Name", schedule.DepartmentId);
            var groups = new SelectList(db.DepartmentGroups.ToList().Where(q => q.Department.Bosses.Contains(currentUser)).ToList(), "Id", "Name", schedule.GroupId).ToList();
            groups.Insert(0,new SelectListItem(){ Value = "", Text = "All"});
            ViewBag.GroupId = groups;

            return View(schedule);
        }
开发者ID:jarolex,项目名称:Personalsystem,代码行数:35,代码来源:SchedulesController.cs

示例10: GetInfoData

 public ActionResult GetInfoData()
 {
     var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
     var currentUser = manager.FindById(User.Identity.GetUserId());
     int id = currentUser.UserInfo.Id;
     return Json(GetPersonalDetails(id), JsonRequestBehavior.AllowGet);
 }
开发者ID:jasonzhewen,项目名称:Capstone,代码行数:7,代码来源:ProfileController.cs

示例11: Read

 public ActionResult Read(int? id)
 {
     if (id == null)
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
     var currentUser = manager.FindById(User.Identity.GetUserId());
     User user;
     using (var dbContext = new YATContext())
     {
         user = dbContext.User.Where(p => p.Id.Contains(currentUser.Id)).FirstOrDefault();
     }
     string userid = user.Id;
     Message message = db.Messages.Find(id);
     Messaging msging = new Messaging();
     var messages = msging.getConversation(message.To.Id, message.From.Id).ToList();
     foreach (Message mess in messages)
     {
         if (mess.ToId.Equals(userid)) 
         { 
             msging.read(mess.To.Id, mess.Id);
         }
     }
     if (message == null)
     {
         return HttpNotFound();
     }
     return View(messages);
 }
开发者ID:contactaditya,项目名称:.NET-Web-Application-Project,代码行数:30,代码来源:MessagesController.cs

示例12: ProcessPayment

        private async Task<string> ProcessPayment(CourseRegistrationModel model, int id)
        {
            var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
            var currentUser = manager.FindById(User.Identity.GetUserId());
            string userEmail = currentUser.Email;
            return await Task.Run(() =>
            {
                Course course = db.Courses.Find(id);
                var myCharge = new StripeChargeCreateOptions
                {
                    Amount = (int)(course.Course_Cost * model.NumberOfParticipants * 100),
                    Currency = "usd",
                    Description = "Description for test charge",
                    ReceiptEmail = userEmail,
                    Source = new StripeSourceOptions
                    {
                        TokenId = model.Token
                    }
                };

                var chargeService = new StripeChargeService("sk_test_yPi2XADkAP3wiS1i6tkjErxZ");
                var stripeCharge = chargeService.Create(myCharge);

                return stripeCharge.Id;
            });
        }
开发者ID:tylerlutz,项目名称:lola,代码行数:26,代码来源:Course_RegistrationController.cs

示例13: Dashboard

        public ActionResult Dashboard()
        {
            var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ProjectContext()));
            ApplicationUser currentUser = manager.FindById(User.Identity.GetUserId());

            if (currentUser == null)
            {
                return Redirect("/");
            }

            ViewBag.UserRole = currentUser.role;

            if(currentUser.role != GlobalRole.REGULAR)
            {
                ViewBag.NewSpaceRequests = db.NewSpaceRequests.ToList<NewSpaceRequest>();
                ViewBag.IncreaseSpaceRequests = db.IncreaseSpaceRequests.ToList<IncreaseSpaceRequest>();
                ViewBag.Spaces = db.Spaces.ToList<Space>();
            }
            else
            {
                //change this to only show the right things
                ViewBag.NewSpaceRequests = db.NewSpaceRequests.ToList<NewSpaceRequest>().FindAll(nsr => nsr.requester_key.Equals(currentUser.Id));
                ViewBag.IncreaseSpaceRequests = db.IncreaseSpaceRequests.ToList<IncreaseSpaceRequest>().FindAll(isr => isr.requester_key.Equals(currentUser.Id));
                ViewBag.UserSpaces = db.UserSpaces.ToList<UserSpace>().FindAll(us => us.user.UserName.Equals(currentUser.UserName));
            }
            return View();
        }
开发者ID:nroach44,项目名称:tothemoon,代码行数:27,代码来源:HomeController.cs

示例14: CreateEmployeeRange

        public List<EmployeeViewModel> CreateEmployeeRange(IEnumerable<EmployeeWFM> inputList)
        {
            List<EmployeeViewModel> viewEmployees = new List<EmployeeViewModel>();
            ApplicationUser user = null;
            EmployeeViewModel employeeView = null;

            using (UserManager<ApplicationUser> userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext())))
            {
                foreach (var inputEmployee in inputList)
                {
                    employeeView = DataMapperView.DoMapping<EmployeeWFM, EmployeeViewModel>(inputEmployee);
                    if (employeeView != null)
                    {
                        if (!String.IsNullOrEmpty(employeeView.IdentityId))
                        {
                            user = userManager.FindById(employeeView.IdentityId);
                            if (user != null)
                            {
                                employeeView.IdentityFirstName = user.FirstName;
                                employeeView.IdentityLastName = user.LastName;
                            }
                        }
                        viewEmployees.Add(employeeView);
                    }
                }
            }

            return viewEmployees;
        }
开发者ID:Sandoryk,项目名称:MVS_projects,代码行数:29,代码来源:ViewModelConverter.cs

示例15: Index

        public ActionResult Index()
        {
            var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));

            if (User.Identity.IsAuthenticated) {

                var currentUser = manager.FindById(User.Identity.GetUserId());

                //ViewBag.TeamName = currentUser.UserInfo.TeamName;
                //ViewBag.UserId = currentUser.UserInfo.Id;
                ViewBag.UserName = currentUser.UserName;
                ViewBag.TeamName = currentUser.TeamName;

                ViewBag.SiteRoot = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Content("~"));

                //var request = HttpContext.Current.Request;

                //int resultId = (from r in db.Results
                //                where r.User.Id == currentUser.Id
                //                select r.Id).First();
                //ViewBag.ResultId = resultId;
            }

            return View();
        }
开发者ID:nvolpe,项目名称:HappyBall,代码行数:25,代码来源:HomeController.cs


注:本文中的UserManager.FindById方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。