Beispiel #1
0
        public void SaveMemberProfile(int MemberID, ViewModels.ProfileViewModel model)
        {
            Member member = GetALL().Include(x => x.Member_Profile).Single(x => x.MemberID == MemberID);

            db.Attach <Member>(member);
            Member_Profile profile = new Member_Profile();

            if (member.Member_Profile != null)
            {
                profile = member.Member_Profile;
            }
            profile.MemberID      = model.MemberID;
            profile.Borthday      = model.Borthday;
            profile.CityCodeValue = model.CityCode;
            var cityCode = 0;

            if (!string.IsNullOrEmpty(model.CityCode))
            {
                cityCode = Convert.ToInt32(model.CityCode.Split(',').Last());
            }
            profile.CityCode      = cityCode;
            profile.Description   = model.Description;
            member.NickName       = model.NickName;
            profile.RealName      = model.RealName;
            profile.Sex           = model.Sex;
            member.Member_Profile = profile;
            db.Commit();
            SetLoginCookie(member);
        }
Beispiel #2
0
        //Profile Section
        public ViewModels.ProfileViewModel GetUserProfile()
        {
            var user = _manager.FindById(HttpContext.Current.User.Identity.GetUserId());

            var viewModel = new ViewModels.ProfileViewModel(user);

            foreach (var userRole in user.Roles.Select(role => _roleRepository.GetById(role.RoleId)))
            {
                viewModel.RoleNames = new[] { userRole.Name };
            }

            return(viewModel);
        }
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            ViewModels.ProfileViewModel p = (ViewModels.ProfileViewModel)validationContext.ObjectInstance;
            if (value == null)
            {
                return(ValidationResult.Success);
            }


            var val = (String)value;

            if (IsNRICValid(val) || IsFINValid(val))
            {
                return(ValidationResult.Success);
            }
            else
            {
                return(new ValidationResult("Invalid NRIC No. Please Check"));
            }
        }
Beispiel #4
0
        public Microsoft.AspNetCore.Mvc.IActionResult EditProfile(System.Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var user = UnitOfWork.BethanyPieShopUnitOfWork.UserRepository.GetUserById(id.Value);

            ViewModels.ProfileViewModel viewModel = new ViewModels.ProfileViewModel()
            {
                Id       = user.Id,
                Username = user.Username,
                EMail    = user.EMail,

                FullName = user.FullName,
                Country  = user.Country,
                State    = user.State,

                City    = user.City,
                Address = user.Address,
                ZipCode = user.ZipCode,

                IsActive    = user.IsActive,
                PhoneNumber = user.PhoneNumber,
                RoleId      = user.RoleId,
                ImageName   = user.ImageName,
            };
            if (user == null)
            {
                return(NotFound());
            }

            //var roles =await roleManager.Roles.ToListAsync();
            //ViewData["RoleId"] = new Microsoft.AspNetCore.Mvc.Rendering.SelectList(roles, "Id", "Name", user.RoleId);
            return(View(viewModel));
        }
        public TrainerProfilePage()
        {
            InitializeComponent();

            BindingContext = profileViewModel = new ViewModels.ProfileViewModel();
        }
Beispiel #6
0
        public Microsoft.AspNetCore.Mvc.IActionResult EditProfile(System.Guid id, ViewModels.ProfileViewModel viewModel)
        {
            if (id != viewModel.Id)
            {
                return(NotFound());
            }
            var orginalUser = UnitOfWork.BethanyPieShopUnitOfWork.UserRepository.GetById(viewModel.Id);

            if (ModelState.IsValid)
            {
                try
                {
                    orginalUser.Id          = viewModel.Id;
                    orginalUser.Username    = viewModel.Username;
                    orginalUser.FullName    = viewModel.FullName;
                    orginalUser.EMail       = viewModel.EMail;
                    orginalUser.Address     = viewModel.Address;
                    orginalUser.City        = viewModel.City;
                    orginalUser.Country     = viewModel.Country;
                    orginalUser.PhoneNumber = viewModel.PhoneNumber;
                    orginalUser.ZipCode     = viewModel.ZipCode;
                    //orginalUser.RoleId = viewModel.RoleId;
                    orginalUser.State    = viewModel.State;
                    orginalUser.IsActive = viewModel.IsActive;

                    if (viewModel.ImageUpload != null)
                    {
                        if (orginalUser.ImageName != null)
                        {
                            var oldfilePath = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "wwwroot", "Images"))
                                              .Root + $@"\{orginalUser.ImageName}";
                            System.IO.File.Delete(oldfilePath);
                        }
                        orginalUser.ImageName = $"{orginalUser.Id}{System.IO.Path.GetExtension(viewModel.ImageUpload.FileName)}";

                        var newfilePath = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "wwwroot", "Images"))
                                          .Root + $@"\{orginalUser.ImageName}";

                        using (System.IO.FileStream fileStream = System.IO.File.Create(newfilePath))
                        {
                            viewModel.ImageUpload.CopyTo(fileStream);
                            fileStream.Flush();
                        }
                    }
                    UnitOfWork.BethanyPieShopUnitOfWork.UserRepository.Update(orginalUser);
                    UnitOfWork.BethanyPieShopUnitOfWork.UserRepository.Save();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (UnitOfWork.BethanyPieShopUnitOfWork.UserRepository.IsExist(id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(ShowProfileInformation), "Account"));
            }
            //var roles =await roleManager.Roles.ToListAsync();
            //ViewData["RoleId"] = new Microsoft.AspNetCore.Mvc.Rendering.SelectList(roles, "Id", "Name", viewModel.RoleId);
            return(View(viewModel));
        }