public ANEventDetailMemberModel GetEventDetailMember(int Id) { //Thread.Sleep(1000); var entity = this.ANDBUnitOfWork.ANEventRepository.GetAll() .Include("ANEventMembers.User.UserProfiles.Image") .FirstOrDefault(x => x.Id == Id); if (entity == null) { return(null); } var listMember = entity.ANEventMembers.Select(x => { var firstUserProfile = x.User.UserProfiles.FirstOrDefault(); var anEventMemberModel = ANEventMemberMapper.ToModel(x); anEventMemberModel.User = UserMapper.ToModel(x.User); if (anEventMemberModel.User != null) { anEventMemberModel.User.Profile = UserProfileMapper.ToModel(firstUserProfile); if (anEventMemberModel.User.Profile != null) { anEventMemberModel.User.Profile.Avatar = ImageMapper.ToModel(firstUserProfile.Image); } } return(anEventMemberModel); } ).ToList(); return(new ANEventDetailMemberModel() { EventId = entity.Id, ANEventMembers = listMember }); }
public ActionResult Index() { ProfileViewModel model = new ProfileViewModel(); AppUser user = GetCurrentUser(); if (user == null) { throw new NullReferenceException("Index: user id null !"); } UserProfile profile = userSrv.Get(user.Id); if (profile == null) { if (User.IsInRole(RoleConstant.RoleRoot)) { profile = new UserProfile(); profile.GivenName = user.Email; profile = userSrv.Edit(profile); } else { throw new NullReferenceException("Index: profile is null!"); } } model = UserProfileMapper.ToViewModel(profile); ProfileInit(model); return(View(model)); }
public ANEventDetailRequestToJoinModel GetEventDetailRequestToJoin(int Id) { if (!this.ANDBUnitOfWork.ANEventRepository.GetAll().Any(x => x.Id == Id && x.UserId.HasValue && x.UserId.Value == this.CurrentUser.Id)) { throw new HttpResponseException(HttpStatusCode.Forbidden); } var requestEntity = this.ANDBUnitOfWork.ANEventRequestToJoinRepository.GetAll() .Include("User.UserProfiles.Image") .Where(x => x.ANEventId.HasValue && x.ANEventId.Value == Id && x.Status.HasValue && x.Status.Value == (int)Common.ANRequestToJoinStatus.Waiting).ToList(); var RTJmodels = requestEntity.Select(x => { var firstUserProfile = x.User.UserProfiles.FirstOrDefault(); var anEventRTJModel = ANEventRequestToJoinMapper.ToModel(x); anEventRTJModel.User = UserMapper.ToModel(x.User); if (anEventRTJModel.User != null) { anEventRTJModel.User.Profile = UserProfileMapper.ToModel(firstUserProfile); if (anEventRTJModel.User.Profile != null) { anEventRTJModel.User.Profile.Avatar = ImageMapper.ToModel(firstUserProfile.Image); } } return(anEventRTJModel); }).ToList(); return(new ANEventDetailRequestToJoinModel() { EventId = Id, ANEventRequestToJoins = RTJmodels }); }
public ActionResult Company(OrgRegisterViewModel model) { if (!ModelState.IsValid) { var errors = ModelState.Select(x => x.Value.Errors) .Where(y => y.Count > 0) .ToList(); ViewBag.ListСlassifikate = new SelectList(classifierService.GetAll.ToList(), "Id", "Name"); return(View(model)); } AppUser user = new AppUser { UserName = model.Email, Email = model.Email, LockoutEnabled = true, LockoutEndDateUtc = DateTime.Now.AddHours(7) }; IdentityResult identResult = UserManager.Create(user, model.Password); if (!identResult.Succeeded) { AddErrorsFromResult(identResult); ViewBag.ListСlassifikate = new SelectList(classifierService.GetAll.ToList(), "Id", "Name"); return(View(model)); } model.SmallPathImage = ImageResize.Resize(model.LogoFile, AppConstants.directoryProfileAvatar, 40, 40); model.LargePathImage = ImageResize.Resize(model.LogoFile, AppConstants.directoryProfileAvatar, 135, 135); model.OwnerId = user.Id; UserManager.AddToRole(user.Id, RoleConstant.RoleCompany); orgService.Edit(OrganizationMapper.ToEntity(model)); profileService.Edit(UserProfileMapper.ToEntity(model)); #if _DEBUG SignInManager.SignIn(user, model.RememberMe, false); return(Redirect("~/")); #endif #if _RELEASE string token = UserManager.GenerateEmailConfirmationToken(user.Id); SendEmail(new EmailVerify { CallbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, token = token }), cid = Guid.NewGuid().ToString(), UserName = user.UserName }, user.Id); return(View("TwoFactorMessage")); #endif }
public ActionResult EditProfile(ProfileViewModel model) { if (!ModelState.IsValid) { return(View(model)); } userSrv.Edit(UserProfileMapper.ToEntity(model), GetCurrentUser().Id); return(Json("success", JsonRequestBehavior.AllowGet)); }
[HttpPut("profile/{userId}")] //1220 public async Task <ActionResult> UpdateStudentProfileByUserId([FromBody] UserProfileInputModel inputModel, int userId) { if (inputModel.Id == userId) { await userStorage.UpdateStudentProfile(UserProfileMapper.ToDataModel(inputModel)); } else { return(BadRequest("Not enough rights!")); } return(Ok()); }
public UserProfileBusinessModel GetUserById(int id) { UserProfileBusinessModel userProfileBusinessModel = new UserProfileBusinessModel(); UserProfile user = uow.UsersProfiles.GetById(id); // UserProfile user = this.uow.UsersProfiles.GetAll().FirstOrDefault(u => u.UserId == id); UserProfileMapper userProfileMapper = new UserProfileMapper(); userProfileBusinessModel = userProfileMapper.Map(user); userProfileBusinessModel.Role = Roles.GetRolesForUser(userProfileBusinessModel.UserName)[0]; return(userProfileBusinessModel); }
public UserProfileBusinessModel GetUserByUserName(string userName) { UserProfileBusinessModel userProfileBusinessModel = new UserProfileBusinessModel(); UserProfile user = this.uow.UsersProfiles.GetAll().FirstOrDefault(u => u.UserName == userName); UserProfileMapper userProfileMapper = new UserProfileMapper(); userProfileBusinessModel = userProfileMapper.Map(user); userProfileBusinessModel.Role = Roles.GetRolesForUser(userProfileBusinessModel.UserName)[0]; return(userProfileBusinessModel); }
public UserProfileModel UpdateUserProfile([FromBody] UserProfileModel model) { var profileEntity = this.ANDBUnitOfWork.UserProfileRepository.GetObject(model.Id); if (profileEntity == null) { return(null); } if (model.Address != null && profileEntity.Address != model.Address) { profileEntity.Address = model.Address; } if (model.BirthDate.HasValue && profileEntity.BirthDate != model.BirthDate) { profileEntity.BirthDate = model.BirthDate; } if (model.Email != null && profileEntity.Email != model.Email) { profileEntity.Email = model.Email; } if (model.FirstName != null && profileEntity.FirstName != model.FirstName) { profileEntity.FirstName = model.FirstName; } if (model.Gender != null && model.Gender.Id != 0 && profileEntity.GenderId.GetValueOrDefault() != model.Gender.Id) { profileEntity.GenderId = model.Gender.Id; } if (model.LastName != null && profileEntity.LastName != model.LastName) { profileEntity.LastName = model.LastName; } if (model.MiddleName != null && profileEntity.MiddleName != model.MiddleName) { profileEntity.MiddleName = model.MiddleName; } if (model.Phone != null && profileEntity.Phone != model.Phone) { profileEntity.Phone = model.Phone; } if (model.Introduction != null && model.Introduction != profileEntity.Introduction) { profileEntity.Introduction = model.Introduction; } this.ANDBUnitOfWork.UserProfileRepository.Save(profileEntity); this.ANDBUnitOfWork.Commit(); return(UserProfileMapper.ToModel(profileEntity)); }
public ActionResult Register(RegisterViewModel model) { if (!ModelState.IsValid) { return(View(model)); } AppUser user = new AppUser { UserName = model.Email, Email = model.Email, LockoutEnabled = true, LockoutEndDateUtc = DateTime.Now.AddHours(7) }; IdentityResult identResult = UserManager.Create(user, model.Password); if (!identResult.Succeeded) { AddErrorsFromResult(identResult); return(View(model)); } else { #if _DEBUG model.OwnerId = user.Id; profileService.Edit(UserProfileMapper.ToEntity(model)); UserManager.AddToRole(user.Id, RoleConstant.RoleUser); SignInManager.SignIn(user, model.RememberMe, false); identResult = UserManager.Update(user); if (!identResult.Succeeded) { AddErrorsFromResult(identResult); return(View(model)); } return(Redirect("~/user/profile")); #endif #if _RELEASE string token = UserManager.GenerateEmailConfirmationToken(user.Id); SendEmail(new EmailVerify { CallbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, token = token }), cid = Guid.NewGuid().ToString(), UserName = user.UserName }, user.Id); return(View("TwoFactorMessage")); #endif } }
public List <ANEventModel> GetEventsInNewFeeds() { var currentUserId = this.CurrentUser.Id; var sandbox = new ANEventSearchingSandbox(this.ANDBUnitOfWork); var results = sandbox.Search(new SearchingSandbox.Model.SearchCriteria() { UserId = currentUserId }); var anEventEntities = this.ANDBUnitOfWork.ANEventRepository.GetAll() .Include("User.UserProfiles.Image") .Include("ANEventImages.Image") .Include("ANEventInformations") .Where(x => results.Contains(x.Id)).ToList() .OrderBy(x => results.IndexOf(x.Id)).ToList(); var favoritedEntities = this.ANDBUnitOfWork.ANEventUserFavouriteRepository.GetAll().Where(x => x.ANEventId.HasValue && results.Contains(x.ANEventId.Value) && x.UserId.HasValue && x.UserId.Value == currentUserId).ToList(); var anEventModels = new List <ANEventModel>(); foreach (var entity in anEventEntities) { var anEventModel = ANEventMapper.ToModel(entity); // get host information if (entity.User != null) { anEventModel.Host = UserMapper.ToModel(entity.User); var firstProfile = entity.User.UserProfiles.FirstOrDefault(); anEventModel.Host.Profile = UserProfileMapper.ToModel(firstProfile); if (anEventModel.Host.Profile != null) { anEventModel.Host.Profile.Avatar = ImageMapper.ToModel(firstProfile.Image); } } // get cover image var coverImageEntity = entity.ANEventImages.Where(x => x.ANEventImageType == (int)Common.ANEventImageType.ANEventCoverImage).OrderBy(x => x.SortPriority).FirstOrDefault(); if (coverImageEntity != null) { anEventModel.CoverPhoto = ImageMapper.ToModel(coverImageEntity.Image); } // get information var information = entity.ANEventInformations.FirstOrDefault(); anEventModel.Information = ANEventInformationMapper.ToModel(information); anEventModel.ANEventUserFavourites = ANEventUserFavouriteMapper.ToModel(favoritedEntities.Where(x => x.ANEventId.HasValue && x.ANEventId.Value == anEventModel.Id)); anEventModels.Add(anEventModel); } return(anEventModels); }
public List <ANEventModel> GetMyEventFavourites() { var currentUserId = this.CurrentUser.Id; var anEventEntities = this.ANDBUnitOfWork.ANEventUserFavouriteRepository.GetAll() .Where(x => x.UserId.HasValue && x.UserId.Value == currentUserId) .Select(x => x.ANEvent) .Include("User.UserProfiles.Image") .Include("ANEventImages.Image") .Include("ANEventInformations.ANEventLocation") .ToList() .OrderByDescending(x => x.CreatedDate).ToList(); var anEventModels = new List <ANEventModel>(); var anEventIds = anEventEntities.Select(x => x.Id).ToList(); var numberOfMembers = this.ANDBUnitOfWork.ANEventRepository.GetAll() .Where(x => anEventIds.Contains(x.Id)) .Select(x => new { Id = x.Id, numberOfMember = x.ANEventMembers.Count() }).ToList(); foreach (var entity in anEventEntities) { var anEventModel = ANEventMapper.ToModel(entity); // get host information if (entity.User != null) { anEventModel.Host = UserMapper.ToModel(entity.User); var firstProfile = entity.User.UserProfiles.FirstOrDefault(); anEventModel.Host.Profile = UserProfileMapper.ToModel(firstProfile); if (anEventModel.Host.Profile != null) { anEventModel.Host.Profile.Avatar = ImageMapper.ToModel(firstProfile.Image); } } // get cover image var coverImageEntity = entity.ANEventImages.Where(x => x.ANEventImageType == (int)Common.ANEventImageType.ANEventCoverImage).OrderBy(x => x.SortPriority).FirstOrDefault(); if (coverImageEntity != null) { anEventModel.CoverPhoto = ImageMapper.ToModel(coverImageEntity.Image); } // get information var information = entity.ANEventInformations.FirstOrDefault(); anEventModel.Information = ANEventInformationMapper.ToModel(information); anEventModel.NumberOfMember = numberOfMembers.Where(x => x.Id == anEventModel.Id).Select(x => x.numberOfMember).FirstOrDefault(); anEventModel.Information.ANEventLocation = ANEventLocationMapper.ToModel(information.ANEventLocation); anEventModels.Add(anEventModel); } return(anEventModels); }
[HttpGet("profile/{userId}")] //1220 public async Task <ActionResult <UserProfileOutputModel> > GetAllLessonByUser(int userId) { if (userId < 1) { return(BadRequest()); } Task <User> getStudentWithSkills = Task.Run(() => userStorage.GetStudentWithSkillsByUserId(userId)); Task <IEnumerable <User> > getTeachers = Task.Run(() => userStorage.GetCurrentTeachersByStudentId(userId)); await Task.WhenAll(getStudentWithSkills, getTeachers); User userWithSkills = await getStudentWithSkills; IEnumerable <User> teachers = await getTeachers; return(Ok(UserProfileMapper.ToOutputModel(userWithSkills, teachers))); }
public ANEventDetailInformationModel GetEventDetailInformation(int Id) { //Thread.Sleep(3000); var entity = this.ANDBUnitOfWork.ANEventRepository.GetAll() .Include("ANEventInformations.ANEventLocation") .Include("User.UserProfiles.Image") .FirstOrDefault(x => x.Id == Id); if (entity == null) { return(null); } var firstInformation = entity.ANEventInformations.FirstOrDefault(); var firstUserProfile = entity.User.UserProfiles.FirstOrDefault(); var host = UserMapper.ToModel(entity.User); if (host != null) { if (firstUserProfile != null) { host.Profile = UserProfileMapper.ToModel(firstUserProfile); } if (firstUserProfile.Image != null) { host.Profile.Avatar = ImageMapper.ToModel(firstUserProfile.Image); } } var informationModel = new ANEventDetailInformationModel() { EventID = entity.Id, EventInformation = firstInformation != null? ANEventInformationMapper.ToModel(firstInformation) : null, Host = host }; if (informationModel.EventInformation != null) { informationModel.EventInformation.ANEventLocation = ANEventLocationMapper.ToModel(firstInformation.ANEventLocation); } return(informationModel); }
/// <summary> /// Gets data of all registered users. /// </summary> /// <returns>List of <see cref="UserProfileBusinessModel"/></returns> public List<UserProfileBusinessModel> GetAllUsers() { List<UserProfileBusinessModel> usersToReturn = new List<UserProfileBusinessModel>(); List<UserProfile> usersToMap; usersToMap = this.uow.UsersProfiles.GetAll().ToList(); UserProfileMapper mapper = new UserProfileMapper(); foreach (var user in usersToMap) { UserProfileBusinessModel businessModel = mapper.Map(user); var roles = Roles.GetRolesForUser(businessModel.UserName); businessModel.Role = (roles.Length == 0 ? string.Empty : roles[0]); businessModel.CreationDate = WebSecurity.GetCreateDate(businessModel.UserName); usersToReturn.Add(businessModel); } return usersToReturn; }
/// <summary> /// Gets data of all registered users. /// </summary> /// <returns>List of <see cref="UserProfileBusinessModel"/></returns> public List <UserProfileBusinessModel> GetAllUsers() { List <UserProfileBusinessModel> usersToReturn = new List <UserProfileBusinessModel>(); List <UserProfile> usersToMap; usersToMap = this.uow.UsersProfiles.GetAll().ToList(); UserProfileMapper mapper = new UserProfileMapper(); foreach (var user in usersToMap) { UserProfileBusinessModel businessModel = mapper.Map(user); var roles = Roles.GetRolesForUser(businessModel.UserName); businessModel.Role = (roles.Length == 0 ? string.Empty : roles[0]); businessModel.CreationDate = WebSecurity.GetCreateDate(businessModel.UserName); usersToReturn.Add(businessModel); } return(usersToReturn); }
public UserProfileModel CreateUserProfile([FromBody] UserProfileModel model) { var entity = new UserProfile() { LastName = model.LastName, MiddleName = model.MiddleName, FirstName = model.FirstName, Phone = model.Phone, Address = model.Address, BirthDate = model.BirthDate, Email = model.Email, GenderId = (model.Gender != null && model.Gender.Id != 0) ? (int?)model.Gender.Id : null, UserId = model.User.Id }; var saveResult = this.ANDBUnitOfWork.UserProfileRepository.Save(entity); this.ANDBUnitOfWork.Commit(); return(UserProfileMapper.ToModel(saveResult)); }
public UserProfileModel GetUserProfile(int Id) { var entity = this.ANDBUnitOfWork.UserProfileRepository.GetAll() .Include(x => x.Image) .FirstOrDefault(x => x.UserId.HasValue && x.UserId.Value == Id); if (entity == null) { return(null); } var model = UserProfileMapper.ToModel(entity); if (model != null) { model.Avatar = ImageMapper.ToModel(entity.Image); model.Gender.GenderName = entity.GenderId == (int)Common.GenderType.Male ? "Nam" : entity.GenderId == (int)Common.GenderType.Female ? "Nữ" : "Chưa xác định"; } return(model); }
public async Task <UserProfileOut> GetAsync(Guid userProfileId) { using (IDBWorker worker = kernel.Get <IDBWorker>()) { UserProfileOut result = new UserProfileOut(); if (!userProfileId.Equals(Guid.Empty)) { UserProfileMapper profile = await worker.UserProfileRepository.FindByIdAsync(userProfileId); result = new UserProfileOut { Id = profile.Id, FirstName = profile.FirstName, Patronymic = profile.Patronymic, Surname = profile.Surname }; } return(result); } }
public ActionResult EditProfile() { var profile = UserProfileMapper.ToViewModel(userSrv.Get(GetCurrentUser().Id)); return(Json(profile, JsonRequestBehavior.AllowGet)); }
public void Have_Something_When_Someting() { var learnignPath = new UserProfileMapper(); learnignPath.ShouldNotBeNull(); }
public UserProfileBusinessModel GetUserByUserName(string userName) { UserProfileBusinessModel userProfileBusinessModel = new UserProfileBusinessModel(); UserProfile user = this.uow.UsersProfiles.GetAll().FirstOrDefault(u => u.UserName == userName); UserProfileMapper userProfileMapper = new UserProfileMapper(); userProfileBusinessModel = userProfileMapper.Map(user); userProfileBusinessModel.Role = Roles.GetRolesForUser(userProfileBusinessModel.UserName)[0]; return userProfileBusinessModel; }
public UserProfileBusinessModel GetUserById(int id) { UserProfileBusinessModel userProfileBusinessModel = new UserProfileBusinessModel(); UserProfile user = uow.UsersProfiles.GetById(id); // UserProfile user = this.uow.UsersProfiles.GetAll().FirstOrDefault(u => u.UserId == id); UserProfileMapper userProfileMapper = new UserProfileMapper(); userProfileBusinessModel = userProfileMapper.Map(user); userProfileBusinessModel.Role = Roles.GetRolesForUser(userProfileBusinessModel.UserName)[0]; return userProfileBusinessModel; }