Beispiel #1
0
        public static UserEntityModel ToEntityModel(this User user, IMediaService mediaService, MediaSettings mediaSettings)
        {
            var userCoverId        = user.GetPropertyValueAs <int>(PropertyNames.DefaultCoverId);
            var userProfileImageId = user.GetPropertyValueAs <int>(PropertyNames.DefaultPictureId);
            var model = new UserEntityModel()
            {
                Id                 = user.Id,
                FirstName          = user.FirstName,
                LastName           = user.LastName,
                Name               = user.Name,
                UserName           = user.UserName,
                Email              = user.Email,
                Active             = user.Active,
                Remarks            = user.Remarks,
                RoleIds            = user.UserRoles.Select(x => x.RoleId).ToList(),
                LastLoginDateUtc   = user.LastLoginDate,
                LastLoginDateLocal = DateTimeHelper.GetDateInUserTimeZone(user.LastLoginDate, DateTimeKind.Utc, user),
                CoverImageId       = userCoverId,
                ProfileImageId     = userProfileImageId
            };

            model.CoverImageUrl   = userCoverId == 0 ? mediaSettings.DefaultUserProfileCoverUrl : mediaService.GetPictureUrl(userCoverId, PictureSizeNames.MediumCover);
            model.ProfileImageUrl = userProfileImageId == 0 ? mediaSettings.DefaultUserProfileImageUrl : mediaService.GetPictureUrl(userProfileImageId, PictureSizeNames.MediumProfileImage);
            return(model);
        }
Beispiel #2
0
        public ActionResult Dashboard()
        {
            #region retrieving the claim values for the currently logged in user (to retrieve him using his/her id)
            ClaimsIdentity currentIdentity = User.Identity as ClaimsIdentity;
            string         modelfullname   = (currentIdentity.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name)).ToString();      //not used
            string         modelusername   = (currentIdentity.Claims.FirstOrDefault(c => c.Type == ClaimTypes.GivenName)).ToString(); //not used
            var            modelid         = int.Parse((currentIdentity.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)).Value);
            #endregion

            UserDetailsViewModel model = null;

            using (PhotoExplorerEntities cx = new PhotoExplorerEntities())
            {
                UserEntityModel entity = cx.Users.FirstOrDefault(u => u.Id == modelid);

                #region mapping necessary properties from entitymodel to the viewmodel
                model = new UserDetailsViewModel()
                {
                    Id             = entity.Id,
                    Username       = entity.Username,
                    Fullname       = entity.Fullname,
                    Albums         = entity.Albums,
                    DateRegistered = entity.DateRegistered,
                    Email          = entity.Email,
                };
                #endregion
            }

            return(View(model));
        }
        public ActionResult Index(string @ref)
        {
            //byte[] time = BitConverter.GetBytes(DateTime.UtcNow.ToBinary());
            //byte[] key = Guid.NewGuid().ToByteArray();
            //string token = Convert.ToBase64String(time.Concat(key).ToArray());
            //Paypal.SendMoney();

            //GetInstragramUrlImage(out List<string> instagramUrlImage);
            _cookie.CheckReferentCookie(Request, Response, @ref);
            using (var dbContext = new MazzaDbContext())
            {
                UserEntityModel model = new UserEntityModel
                {
                    Users             = dbContext.Users.ToList(),
                    Deposits          = dbContext.Deposits.ToList(),
                    Withdrawals       = dbContext.Withdrawals.ToList(),
                    InstagramUrlImage = new List <string>
                    {
                        "https://www.bucknell.edu/Images/Depts/Communication/Branding/ColorPalette-PaperWhite-200x200.jpg",
                        "https://www.bucknell.edu/Images/Depts/Communication/Branding/ColorPalette-PANTONE305C-200x200.jpg",
                        "https://www.bucknell.edu/Images/Depts/Communication/Branding/ColorPalette-PANTONE640C-200x200.jpg",
                        "https://www.bucknell.edu/Images/Depts/Communication/Branding/ColorPalette-BucknellBlue-200x200.jpg",
                        "https://www.bucknell.edu/Images/Depts/Communication/Branding/ColorPalette-PANTONE137C-200x200.jpg"
                    }
                };
                return(View(model));
            }
        }
Beispiel #4
0
        protected ActionResult Create0(UserEntityModel model)
        {
            //entity.CreatedAt = DateTime.Now;
            var responseInsert = UserBusinessLogic.Add(model.ToEntity());

            return(Json(responseInsert));
        }
Beispiel #5
0
        protected ActionResult Update0(UserEntityModel model)
        {
            //entity.UpdatedAt = DateTime.Now;
            var responseEdit = UserBusinessLogic.Edit(model.ToEntity());

            return(Json(responseEdit));
        }
        public ActionResult Login(UserViewModel model)
        {
            UserEntityModel userToLogin = null;

            userToLogin = repo.LoginUser(model.Email, model.Password);

            if (userToLogin != null)
            {
                //Refaktorera till en egen metod
                var identity = new ClaimsIdentity(new[]
                {
                    new Claim(ClaimTypes.Name, (userToLogin.FirstName + " " + userToLogin.LastName)),
                    new Claim(ClaimTypes.Email, userToLogin.Email),
                    new Claim(ClaimTypes.Sid, userToLogin.id.ToString()),
                    new Claim(ClaimTypes.Role, UserIsAdmin(userToLogin) ? "Admin" : "User")
                },
                                                  "ApplicationCookie");

                var ctx         = Request.GetOwinContext();
                var authManager = ctx.Authentication;


                //Skicka in AuthenticationOptions om man vill ha persistent eller expiration date.
                authManager.SignIn(identity);

                return(Content("/Home/Index"));
            }
            ModelState.AddModelError("", "Invalid Email or Password");
            return(Content("Invalid Email or Password"));
        }
        public static UserEntityModel ToEntityModel(this User user, IMediaService mediaService, MediaSettings mediaSettings)
        {
            var userCoverId        = user.GetPropertyValueAs <int>(PropertyNames.DefaultCoverId);
            var userProfileImageId = user.GetPropertyValueAs <int>(PropertyNames.DefaultPictureId);
            var model = new UserEntityModel()
            {
                Id             = user.Id,
                FirstName      = user.FirstName,
                LastName       = user.LastName,
                Name           = user.Name,
                UserName       = user.UserName,
                Email          = user.Email,
                Active         = user.Active,
                Remarks        = user.Remarks,
                RoleIds        = user.UserRoles.Select(x => x.RoleId).ToList(),
                CoverImageId   = userCoverId,
                ProfileImageId = userProfileImageId
            };

            //TODO: Put capability check instead of administration check, that'd be more scalable
            if (ApplicationContext.Current.CurrentUser.IsAdministrator() && user.LastLoginDate.HasValue)
            {
                model.LastLoginDateUtc   = user.LastLoginDate;
                model.LastLoginDateLocal = DateTimeHelper.GetDateInUserTimeZone(user.LastLoginDate.Value,
                                                                                DateTimeKind.Utc, user);
            }
            model.CoverImageUrl   = userCoverId == 0 ? mediaSettings.DefaultUserProfileCoverUrl : mediaService.GetPictureUrl(userCoverId, PictureSizeNames.MediumCover) ?? mediaSettings.DefaultUserProfileCoverUrl;
            model.ProfileImageUrl = userProfileImageId == 0 ? mediaSettings.DefaultUserProfileImageUrl : mediaService.GetPictureUrl(userProfileImageId, PictureSizeNames.MediumProfileImage) ?? mediaSettings.DefaultUserProfileImageUrl;
            return(model);
        }
        public BaseController(IHttpContextAccessor httpContextAccessor,
                              IConfiguration configuration)
        {
            CdnPath = configuration.GetSection("Application").GetSection("CDN").Value;
            var userManager = new UserManager(Db);

            CurrentUserEntity = userManager.GetCurrentUser(httpContextAccessor.HttpContext.User);
        }
Beispiel #9
0
 public void CreateUser(UserEntityModel entity)
 {
     if (entity == null)
     {
         throw new ArgumentNullException(nameof(entity));
     }
     entity.Id = _currentId++;
     _usersStorage.Add(entity);
 }
        private bool UserIsAdmin(UserEntityModel user)
        {
            if (user.guid == Guid.Parse("{3027308A-5C93-4694-869A-BA40F042F94C}"))
            {
                return(true);
            }

            return(false);
        }
Beispiel #11
0
        public void Add(UserEntityModel userToBeRegistered)
        {
            using (PhotoExplorerEntities _context = new PhotoExplorerEntities())
            {
                _context.Users.Add(userToBeRegistered);

                _context.SaveChanges();
            }
        }
        private IdentityUserViewModel GetIdentityUserViewModel(UserEntityModel model)
        {
            if (model == null)
            {
                return(null);
            }

            var viewModel = model.ToViewModel <UserEntityModel, IdentityUserViewModel>();

            return(viewModel);
        }
Beispiel #13
0
        public static UserViewModel EntityToModel(UserEntityModel entity)
        {
            var model = new UserViewModel();

            model.FirstName = entity.FirstName;
            model.LastName  = entity.LastName;
            model.Email     = entity.Email;
            model.guid      = entity.guid;
            model.id        = entity.id;

            return(model);
        }
Beispiel #14
0
 public UserEntityModel GetUser(int IserModelId)
 {
     using (PhotoExplorerEntities _context = new PhotoExplorerEntities())
     {
         UserEntityModel user = _context.Users
                                .Where(u => u.Id == IserModelId)
                                .Include(u => u.Albums
                                         .Select(p => p.Photos
                                                 .Select(c => c.Comments))) //neccessary to include the albums
                                .FirstOrDefault();
         return(user);
     }
 }
Beispiel #15
0
        public static UserEntityModel ModelToEntity(UserViewModel model)
        {
            var user = new UserEntityModel();

            user.FirstName = model.FirstName;
            user.LastName  = model.LastName;
            user.Email     = model.Email;
            user.guid      = model.guid;
            user.Password  = model.Password;
            user.id        = model.id;

            return(user);
        }
Beispiel #16
0
 public ActionResult DeleteUser(UserEntityModel user)
 {
     try
     {
         var UserMap = AutoMapper.Mapper.Map <UserEntityModel, User>(user);
         userDetailsBL.DeleteUser(UserMap);
         return(RedirectToAction("ViewUser"));
     }
     catch
     {
         return(RedirectToAction("Error", "Error"));
     }
 }
Beispiel #17
0
        protected void AddAccountMembership(UserEntityModel user, AccountEntityModel account)
        {
            // Add Account Membership.
            var userAccount = new UserAccountEntityModel
            {
                User      = user,
                Account   = account,
                CreatedBy = User
            };

            Context.UserAccounts.Add(userAccount);
            Context.SaveChanges();
            Trace.WriteLine($"Added Account Membership -> {user.UserName} => {account.Name}");
        }
Beispiel #18
0
        protected void AddGroupAssignment(UserEntityModel user, GroupEntityModel group)
        {
            // Add Group Assignment.
            var groupAssign = new UserGroupEntityModel
            {
                User      = user,
                Group     = group,
                CreatedBy = User
            };

            Context.UserGroups.Add(groupAssign);
            Context.SaveChanges();
            Trace.WriteLine($"Added Group Assignment -> {user.UserName} => {group.Name}");
        }
Beispiel #19
0
        protected void AddShopMembership(UserEntityModel user, ShopEntityModel shop)
        {
            // Add Shop Membership.
            var userShop = new UserShopEntityModel
            {
                User      = user,
                Shop      = shop,
                CreatedBy = User
            };

            Context.UserShops.Add(userShop);
            Context.SaveChanges();
            Trace.WriteLine($"Added Shop Membership -> {user.UserName} => {shop.Name}");
        }
Beispiel #20
0
        public static UserDetailsViewModel EntityToModel(UserEntityModel entity)
        {
            UserDetailsViewModel model = new UserDetailsViewModel()
            {
                Id             = entity.Id,
                Username       = entity.Username,
                Fullname       = entity.Fullname,
                Albums         = entity.Albums,
                DateRegistered = entity.DateRegistered,
                Email          = entity.Email,
            };

            return(model);
        }
Beispiel #21
0
 public ActionResult Index(string @ref)
 {
     _cookie.CheckReferentCookie(Request, Response, @ref);
     using (var dbContext = new MazzaDbContext())
     {
         UserEntityModel model = new UserEntityModel
         {
             Users       = dbContext.Users.ToList(),
             Deposits    = dbContext.Deposits.ToList(),
             Withdrawals = dbContext.Withdrawals.ToList(),
         };
         return(View(model));
     }
 }
Beispiel #22
0
        public ActionResult PhotoDetails(int Id)
        {
            //todo: retrieve this photos uploader
            #region retrieve photo to show
            PhotoDetailsViewModel model = null;

            using (PhotoExplorerEntities cx = new PhotoExplorerEntities())
            {
                PhotoEntityModel entity = cx.Photos
                                          .Where(p => p.Id == Id)
                                          .FirstOrDefault();

                ///todo: make this more effective..
                #region retrieve uploader of photoentity
                UserEntityModel photoOwnerEntity = null;
                foreach (var user in cx.Users)
                {
                    foreach (var album in user.Albums)
                    {
                        foreach (var photo in album.Photos)
                        {
                            if (photo.Id == Id)
                            {
                                photoOwnerEntity = user;
                                break;
                            }
                        }
                    }
                }
                #endregion


                model = new PhotoDetailsViewModel()
                {
                    Id          = entity.Id,
                    Name        = entity.Name,
                    FileName    = entity.FileName,
                    DateCreated = entity.DateCreated,
                    DateChanged = entity.DateChanged,
                    Album       = entity.Album,
                    Comments    = entity.Comments, //due to us already having the model collection initialized in the photodetailsviewmodel class, we only have to transfer the collection VALUES from the entity collection to the model collection.
                    Description = entity.Description,
                    User        = photoOwnerEntity,
                };
            }
            #endregion

            return(View(model));
        }
Beispiel #23
0
        protected UserEntityModel AddUser(string userName)
        {
            // Create Test User.
            var user = new UserEntityModel
            {
                Email             = userName,
                UserName          = userName,
                CreatedByUserGuid = Guid.Empty
            };

            Context.Users.Add(user);
            Context.SaveChanges();
            Trace.WriteLine($"Added Test User -> {user.UserName}");
            return(Context.Users.FirstOrDefault(u => u.UserName == userName));
        }
Beispiel #24
0
            public static void Create(string guid, string username, string alias, IEnumerable <UserEntityModel.Claim> claims)
            {
                var user = new UserEntityModel {
                    MasterGuid     = guid,
                    IsEnabled      = true,
                    MasterUsername = username,
                    MasterAlias    = alias,
                    Claims         = claims
                };
                var keys = GenerateUsersKeys(guid, "rsa", "20048");

                user.PublicKey  = keys.Item1;
                user.PrivateKey = keys.Item2;
                Session.New.Set(user);
            }
Beispiel #25
0
        private void RefreshMyRoles()
        {
            // Load SignIn Manager.
            using (var signinMgr = HttpContext.GetOwinContext().Get <ApplicationSignInManager>())
            {
                var user = new UserEntityModel
                {
                    Id       = Factory.User.UserGuid,
                    UserName = Factory.User.UserName
                };

                // Reauthenticate to Reload Current User Roles.
                signinMgr.SignIn(user, false, false);
            }
        }
Beispiel #26
0
        public async Task <IdentityResult> CreateUserAsync(UserEntityModel user, string password = null)
        {
            _dateService.SetDateCreatedNow(ref user);
            IdentityResult res;

            if (password != null)
            {
                res = await _userManager.CreateAsync(user, password);
            }
            else
            {
                res = await _userManager.CreateAsync(user);
            }

            return(res);
        }
Beispiel #27
0
        public ActionResult Comment(int id, string txt_comment)
        {
            PhotoDetailsViewModel model = null;

            using (PhotoExplorerEntities cx = new PhotoExplorerEntities())
            {
                // retrieve currently logged in user
                ClaimsIdentity  currentIdentity = User.Identity as ClaimsIdentity;
                int             userid          = int.Parse(currentIdentity.Claims.FirstOrDefault(u => u.Type == ClaimTypes.NameIdentifier).Value);
                UserEntityModel loggedInEntity  = cx.Users.FirstOrDefault(u => u.Id == userid);

                // initialize new comment entity
                CommentEntityModel commentModel = new CommentEntityModel()
                {
                    DateCreated = DateTime.Now,
                    Comment     = txt_comment,
                    Commenter   = loggedInEntity.Username,
                };

                // retrieve the photo entity commented on
                PhotoEntityModel entity = cx.Photos
                                          .Where(p => p.Id == id)
                                          .FirstOrDefault();

                entity.Comments.Add(commentModel);

                cx.SaveChanges();

                //mapping
                model = new PhotoDetailsViewModel()
                {
                    Name        = entity.Name,
                    Album       = entity.Album,
                    DateCreated = entity.DateCreated,
                    FileName    = entity.FileName,
                    Description = entity.Description,
                    Id          = entity.Id,
                    User        = loggedInEntity,
                    Comments    = entity.Comments,
                };
            }

            /*
             *  note: only updating portion of the page by using partial view (with the NEW model)
             */
            return(PartialView("_PhotoComments", model));
        }
Beispiel #28
0
        protected void AddUserRole(UserEntityModel user, ApplicationRoles role)
        {
            // Add User Roles.
            var showAllRole = new UserRoleEntityModel
            {
                RoleId = role.GetEnumGuid(),
                User   = user
            };

            Context.UserRoles.Add(showAllRole);
            Context.SaveChanges();

            // Reload Factory.
            Factory = new ServiceFactory(Context, Identity);

            Trace.WriteLine($"Added '{role}' Role to User -> {user.UserName}");
        }
Beispiel #29
0
        public void RegisterNewUser(string fullname, string username, string password, string email)
        {
            using (PhotoExplorerEntities cx = new PhotoExplorerEntities())
            {
                UserEntityModel entity = new UserEntityModel()
                {
                    Fullname = fullname,
                    Username = username,
                    Password = password,
                    Email    = email,
                };

                cx.Users.Add(entity);

                cx.SaveChanges();
            }
        }
Beispiel #30
0
        public void AddorUpdateUser(UserEntityModel userentitymodel)
        {
            if (userentitymodel.UserID > 0)
            {
                // update
                var userdata = _unitOfWork.Repository <User>().Table().FirstOrDefault(c => c.UserId == userentitymodel.UserID);

                if (userdata == null)
                {
                    throw new Exception("User not found");
                }

                userdata.UserName         = userentitymodel.Name ?? userdata.UserName;
                userdata.UserEmailId      = userentitymodel.Email ?? userdata.UserEmailId;
                userdata.UserMobileNo     = userentitymodel.MobileNo ?? userdata.UserMobileNo;
                userdata.UserRoleId       = userentitymodel.RoleId ?? userdata.UserRoleId;
                userdata.UserStatus       = userentitymodel.Status ?? userdata.UserStatus;
                userdata.UserDelete       = userentitymodel.IsDeleted ?? userdata.UserDelete;
                userdata.UserApprovedBy   = userentitymodel.UserApprovedBy ?? userdata.UserApprovedBy;
                userdata.UserRejectedBy   = userentitymodel.UserRejectedBy ?? userdata.UserRejectedBy;
                userdata.LastModifiedDate = DateTime.Now;
                userdata.LastModifiedBy   = 1;
                _unitOfWork.Repository <User>().Update(userdata);
                _unitOfWork.Save();
            }
            else
            {
                Mapper.CreateMap <UserEntityModel, User>();
                var userdata = Mapper.Map <UserEntityModel, User>(userentitymodel);

                userdata.UserName           = userentitymodel.Name;
                userdata.UserCompany        = userentitymodel.Company;
                userdata.UserMobileNo       = userentitymodel.MobileNo;
                userdata.UserEmailId        = userentitymodel.Email;
                userdata.UserPassword       = userentitymodel.Password;
                userdata.UserEmailConfirmed = false;
                userdata.UserPhoneConfirmed = false;
                userdata.UserStatus         = false;
                userdata.UserDelete         = false;
                userdata.CreatedBy          = userentitymodel.CreatedBy;
                userdata.CreatedDate        = DateTime.Now;
                _unitOfWork.Repository <User>().Add(userdata);
                _unitOfWork.Save();
            }
        }
Beispiel #31
0
 public void InsertUser(UserEntityModel user)
 {
     context.UserDbSet.Add(user);
     context.SaveChanges();
 }
Beispiel #32
0
 public void Updateuser(UserEntityModel user)
 {
     context.Entry(user).State = EntityState.Modified;
     context.SaveChanges();
 }