public ActionResult EditProfile()
        {
            EditProfileVM model = new EditProfileVM();

            using (TruckTransportDbContext _db = new TruckTransportDbContext())
            {
                var dispatcherUser = _db.dispecerlogin.AsNoTracking().Where(x => x.dispecerlogin_id == _dispatcherUserID).SingleOrDefault();

                if (dispatcherUser != null)
                {
                    model.DispatcherUserID = dispatcherUser.dispecerlogin_id;

                    model.DispatcherUser = new EditPersonalInfoVM {
                        DispatcherUserID = dispatcherUser.dispecerlogin_id,
                        Email            = dispatcherUser.email,
                        Username         = dispatcherUser.username,
                        LastLoginTime    = dispatcherUser.lastlogin.ToString()
                    };

                    model.DispatcherPassword = new ChangePasswordVM();
                }
            }

            return(View(viewName: "EditProfile", model: model));
        }
Exemplo n.º 2
0
        public static List <SelectListItem> GetCountriesList(
            this EditProfileVM registrationVM)
        {
            var result    = new List <SelectListItem>();
            var countries = registrationVM.Countries;
            var checkd    = false;

            foreach (var country in countries)
            {
                if (registrationVM.UserAddress.CountryID != 0)
                {
                    if (country.Country_ID == registrationVM.UserAddress.CountryID)
                    {
                        checkd = true;
                    }
                }
                else
                {
                    if (country.CountryName == "Российская Федерация")
                    {
                        checkd = true;
                    }
                }
                result.Add(
                    new SelectListItem
                {
                    Selected = checkd,
                    Text     = country.CountryName,
                    Value    = country.Country_ID.ToString()
                });
                checkd = false;
            }
            return(result);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> EditProfile(EditProfileVM model)

        {
            if (!ModelState.IsValid)
            {
                return(PartialView("_EditProfile", model));
            }
            var user = await userManager.FindByIdAsync(model.Id);

            if (user == null)
            {
                ViewBag.ErrorMessage = "User cannot be found";
                return(View("NotFound"));
            }
            else
            {
                user.FirstName = model.FirstName;
                user.LastName  = model.LastName;

                var result = await userManager.UpdateAsync(user);

                if (result.Succeeded)
                {
                    return(PartialView("_EditProfile", model));
                }

                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }

                return(View("_EditProfile", model));
            }
        }
Exemplo n.º 4
0
        public ActionResult Edit(EditProfileVM model)
        {
            var u = db.Users.Find(model.Id);

            if (u == null)
            {
                return(RedirectToAction("Edit"));
            }

            if (ModelState.IsValid)
            {
                u.name       = model.name;
                u.username   = model.username;
                u.email      = model.email;
                u.contact_no = model.contact_no;
                u.password   = model.password;

                if (model.Photo != null)
                {
                    DeletePhoto(u.photo);
                    u.photo = SavePhoto(model.Photo);
                }

                db.SaveChanges();
                TempData["Info"] = "Profile edited successfully!";
                return(RedirectToAction("Index", "Home"));
            }
            model.PhotoUrl = u.photo;
            return(View(model));
        }
Exemplo n.º 5
0
        public IActionResult EditProfile()
        {
            current_user = repo.GetUserById(User.Identity.Name);
            EditProfileVM edit_user = new EditProfileVM();

            edit_user.Login   = current_user.Login;
            edit_user.Email   = current_user.Email;
            edit_user.Picture = current_user.Picture;
            edit_user.tags    = repo.GetUserTags(current_user.Id).Select(x => x.Title).ToArray();
            return(View(edit_user));
        }
Exemplo n.º 6
0
        private void UpdateAddress(EditProfileVM model, User user)
        {
            var userAddresses = model.IsCompany
                ? user.Company.UserAddresses
                : user.UserAddresses;

            /*   var contactType = model.IsCompany
             *     ? ContactTypes.LegalAddress
             *     : ContactTypes.Address;*/
            UpdateAddress(userAddresses, model.UserAddress);
        }
Exemplo n.º 7
0
        public EditProfileVM GetEditProfileVM()
        {
            var user   = AuthService.CurrentUser;
            var result =
                new EditProfileVM
            {
                User = AuthService.CurrentUser,
            };

            SetDictionaries(result);

            if (result.User != null)
            {
                var contactsVM = result.Contacts;
                if (user.IsCompany)
                {
                    contactsVM.Phone = GetContact(user.Company.UserContacts,
                                                  ContactTypes.Phone);
                    contactsVM.Mobile =
                        GetContact(user.Company.UserContacts, ContactTypes.Mobile);
                    contactsVM.WorkPhone =
                        GetContact(user.Company.UserContacts, ContactTypes.WorkPhone);
                    result.UserAddress = user.Company.UserAddresses.FirstOrDefault();
                }
                else
                {
                    result.UserAddress = user.UserAddresses.FirstOrDefault();

                    contactsVM.Socials = GetSocials(user.UserContacts);

                    InitPhones(user, contactsVM);
                }
            }
            else
            {
                result.User = new User();
            }

            if (result.UserAddress == null)
            {
                result.UserAddress = new UserAddress();
            }
            if (result.Company == null)
            {
                result.Company = new Company();
            }
            result.ContactTypes = UserContractTypeService.GetAll()
                                  .Where(uct => ContactTypes.ForProfile().Contains(uct.ContactTypeID))
                                  .ToList();


            return(result);
        }
Exemplo n.º 8
0
 public EditProfilePage()
 {
     InitializeComponent();
     FirstName.Text = SignedInUser.User.FirstName;
     LastName.Text  = SignedInUser.User.LastName;
     Email.Text     = SignedInUser.User.Email;
     Phone.Text     = SignedInUser.User.PhoneNumber;
     Username.Text  = SignedInUser.User.Username;
     GitHub.Text    = SignedInUser.User.GitHubURL;
     LinkedIn.Text  = SignedInUser.User.LinkedinURL;
     BindingContext = model = new EditProfileVM(SignedInUser.User);
 }
Exemplo n.º 9
0
        public ActionResult Edit(EditProfileVM model)
        {
            var u = db.Users.Find(model.Id);

            if (u == null)
            {
                TempData["info"] = model.Id;
                return(RedirectToAction("Edit", "User"));
            }

            if (ModelState.IsValid)
            {
                u.name       = model.name;
                u.username   = model.username;
                u.email      = model.email;
                u.contact_no = model.contact_no;
                if (model.newPassword != null)
                {
                    u.password = HashPassword(model.newPassword);
                }

                if (model.Photo != null)
                {
                    DeletePhoto(u.photo);
                    u.photo = SavePhoto(model.Photo);
                }

                if (model.webPhoto != null)
                {
                    u.photo = model.webPhoto;
                }


                try
                {
                    db.SaveChanges();
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            System.Diagnostics.Debug.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }
                TempData["Info"] = "Profile edited successfully!";
                return(RedirectToAction("Edit", "User"));
            }
            return(View(model));
        }
Exemplo n.º 10
0
        public async Task <IActionResult> EditStudentProfile([FromBody] EditProfileVM student)
        {
            //Get Request's User
            var claimsIdentity = (ClaimsIdentity)this.User.Identity;

            if (!claimsIdentity.IsAuthenticated)
            {
                return(Unauthorized());
            }
            //Get Student Profile
            var claim     = claimsIdentity.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier);
            var userEmail = claim.Value;
            var User      = await _userManager.FindByEmailAsync(userEmail);

            student.ApplicationUserId = User.Id;

            Student studentToEdit = new Student();

            studentToEdit.Id                = student.Id;
            studentToEdit.Info              = student.Info;
            studentToEdit.Title             = student.Title;
            studentToEdit.Universty         = student.Universty;
            studentToEdit.School            = student.School;
            studentToEdit.SchholYearFrom    = student.SchholYearFrom;
            studentToEdit.SchholYearTo      = student.SchholYearTo;
            studentToEdit.UniverstyYearFrom = student.UniverstyYearFrom;
            studentToEdit.UniverstyYearTo   = student.UniverstyYearTo;
            studentToEdit.ApplicationUserId = User.Id;
            studentToEdit.Image             = student.Image;
            ApplicationUser userToEdit = new ApplicationUser();

            userToEdit           = User;
            userToEdit.Gender    = student.Gender;
            userToEdit.BirthDate = Convert.ToDateTime(student.Birthdate);
            userToEdit.Name      = student.Username;
            var updatedProfileInfo = _profileSrv.EditProile(studentToEdit, userToEdit);

            return(Ok(new { Status = "Success", ProfileInfo = new {
                                Image = updatedProfileInfo.Image,
                                Info = updatedProfileInfo.Info,
                                School = updatedProfileInfo.School,
                                Universty = updatedProfileInfo.Universty,
                                Username = User.Name,
                                SchoolYearFrom = student.SchholYearFrom,
                                SchoolYearTo = student.SchholYearTo,
                                UniverstyYearFrom = student.UniverstyYearFrom,
                                UniverstyYearTo = student.UniverstyYearTo,
                                Gender = User.Gender,
                                BirthDate = User.BirthDate.ToString("MM/dd/yyyy")
                            } }));
        }
Exemplo n.º 11
0
 public IActionResult EditProfile(EditProfileVM editprof)
 {
     current_user = repo.GetUserById(User.Identity.Name);
     if (ModelState.IsValid)
     {
         repo.UpdateInfoUser(editprof, current_user.Id);
         return(RedirectToAction("Profile"));
     }
     else
     {
         ModelState.AddModelError("", "Некорректные логин и(или) пароль");
     }
     return(View(editprof));
 }
Exemplo n.º 12
0
        public IActionResult Edit(EditProfileVM model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = context.ApplicationUsers.Find(userId);

            user.Alias = model.Alias;
            context.SaveChanges();

            return(RedirectToAction(nameof(ProfileController.Index)));
        }
Exemplo n.º 13
0
        // Edit users
        public ActionResult Edit()
        {
            var u = db.Users.FirstOrDefault(x => x.username == User.Identity.Name);

            var model = new EditProfileVM
            {
                Id         = u.Id,
                username   = u.username,
                name       = u.name,
                contact_no = u.contact_no.Trim(),
                email      = u.email,
                PhotoUrl   = u.photo
            };

            return(View(model));
        }
Exemplo n.º 14
0
        public async Task <IActionResult> EditProfile(string id)
        {
            var user = await userManager.FindByIdAsync(id);

            if (user == null)
            {
                ViewBag.ErrorMessage = $"User with Id = {id} cannot be found";
                return(View("NotFound"));
            }

            var model = new EditProfileVM
            {
                FirstName = user.FirstName,
                LastName  = user.LastName,
            };

            return(PartialView("_EditProfile", model));
        }
        private string ProcessUploadedFile(EditProfileVM model)
        {
            string uniqueFileName = null;

            if (model.Picture != null)
            {
                string uploadsFolder = Path.Combine(_hostEnvironment.WebRootPath + "/images");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Picture.FileName;
                string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                using var fileStream = new FileStream(filePath, FileMode.Create);
                model.Picture.CopyTo(fileStream);
            }
            else
            {
                return(uniqueFileName);
            }

            return(uniqueFileName);
        }
Exemplo n.º 16
0
        private void UpdateContacts(EditProfileVM model, User user)
        {
            var contacts = model.IsCompany
                ? user.Company.UserContacts
                : user.UserContacts;
            var contactsVM = model.Contacts;

            UpdatePhones(contacts, contactsVM);
            if (!model.IsCompany)
            {
                if (contactsVM.Socials != null)
                {
                    foreach (var contact in contactsVM.Socials)
                    {
                        UpdateContact(contacts, contact.Contact, contact.ContactTypeID);
                    }
                }
            }
        }
Exemplo n.º 17
0
        public void Update(EditProfileVM model)
        {
            model.UserAddress.ContactTypeID = ContactTypes.Address;
            /*model.IsCompany ? ContactTypes.LegalAddress : */
            var currentUser = AuthService.CurrentUser;

            if (currentUser == null)
            {
                CreateProfile(model);
                return;
            }

            var user = UserService.GetByPK(currentUser.UserID);

            user.Update(model.User,
                        x => x.LastName,
                        x => x.SecondName,
                        x => x.FirstName
                        );
            user.Update(model.User,
                        x => x.HideCourses,
                        x => x.EngFullName,
                        x => x.BirthDate,
                        x => x.HideContacts);
            if (model.IsCompany)
            {
                if (user.Company == null)
                {
                    var company = model.Company;
                    model.Company.Users.Clear();
                    user.Company = company;
                }
                else
                {
                    user.Company.UpdateByMeta(model.Company, x => x.CompanyID);
                }
            }
            UpdateAddress(model, user);
            UpdateContacts(model, user);
            UserService.SubmitChanges();
            AuthService.RefreshUser();
        }
Exemplo n.º 18
0
        private void CreateProfile(EditProfileVM model)
        {
            var user     = model.User;
            var contacts = model.Company != null
              ? user.Company.UserContacts
              : user.UserContacts;
            var userAddresses = model.Company != null
                ? user.Company.UserAddresses
                : user.UserAddresses;

            if (model.Contacts.Phone != null)
            {
                contacts.Add(new UserContact(ContactTypes.Phone, model.Contacts.Phone));
            }
            if (model.Contacts.Mobile != null)
            {
                contacts.Add(
                    new UserContact(ContactTypes.Mobile, model.Contacts.Mobile));
            }
            if (model.Contacts.WorkPhone != null)
            {
                contacts.Add(
                    new UserContact(ContactTypes.WorkPhone, model.Contacts.WorkPhone));
            }
            userAddresses.Add(model.UserAddress);

            /*  if(model.IsCompany)
             * {*/

            /*    contacts.Add( new UserContact(ContactTypes.Fax, model.Contacts.Fax));
             *  contacts.Add( new UserContact(ContactTypes.LegalAddress,
             *      model.LegalAddress));*/
            /*     }
             *   else
             *   {*/

//            }

            UserService.CreateUser(user);
            AuthService.SignIn(user.Email, true);
            OrderService.UpdateSessionOrderUser();
        }
Exemplo n.º 19
0
        // Edit users
        public ActionResult Edit()
        {
            var name = User.Identity.Name;
            var u    = db.Users.Where(x => x.username == name).FirstOrDefault();

            if (u == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            var Model = new EditProfileVM
            {
                Id         = u.Id,
                username   = u.username,
                name       = u.name,
                contact_no = u.contact_no.Trim(),
                email      = u.email,
                password   = u.password,
                PhotoUrl   = u.photo
            };

            return(View(Model));
        }
        public async Task <IActionResult> EditProfile(EditProfileVM model)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", "Please fill out the form correctly");
                return(View(model));
            }
            else
            {
                var editedUser = await userManager.FindByIdAsync(model.Id);

                if (editedUser == null)
                {
                    return(NotFound());
                }
                else
                {
                    editedUser.Id          = model.Id;
                    editedUser.Email       = model.Email;
                    editedUser.FirstName   = model.FirstName;
                    editedUser.LastName    = model.LastName;
                    editedUser.MiddleName  = model.MiddleName;
                    editedUser.PhoneNumber = model.PhoneNumber;
                    editedUser.UserName    = model.Email;
                    if (model.Picture != null)
                    {
                        if (model.PictureUrl != null)
                        {
                            string filePath = Path.Combine(_hostEnvironment.WebRootPath, "images", model.PictureUrl);
                            System.IO.File.Delete(filePath);
                        }
                        editedUser.PictureUrl = ProcessUploadedFile(model);
                    }
                    else
                    {
                        if (model.DeleteOldPicture)
                        {
                            if (model.PictureUrl != null)
                            {
                                string filePath = Path.Combine(_hostEnvironment.WebRootPath, "images", model.PictureUrl);
                                System.IO.File.Delete(filePath);
                                editedUser.PictureUrl = null;
                            }
                            else
                            {
                                editedUser.PictureUrl = null;
                            }
                        }
                    }
                    var result = await userManager.UpdateAsync(editedUser);

                    if (result.Succeeded)
                    {
                        return(RedirectToAction("Index"));
                    }
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError("", error.Description);
                    }
                    return(View(model));
                }
            }
        }
 public EditProfileWindow(object prof)
 {
     InitializeComponent();
     DataContext = new EditProfileVM(prof);
 }
Exemplo n.º 22
0
 public void SetDictionaries(EditProfileVM result)
 {
     result.Countries = DictionariesService.GetCountries();
 }
Exemplo n.º 23
0
            public async Task<JsonResult> Edit(EditProfileVM model)
            {
                if (ModelState.IsValid)
                {
                    var result = await _userService.UpdateProfileAsync(model);

                    return Json(result, JsonRequestBehavior.DenyGet);

                }
                return Json(false, JsonRequestBehavior.DenyGet);

            }
Exemplo n.º 24
0
        public async Task<bool> UpdateProfileAsync(EditProfileVM model)
        {
            var user = await _users.FindByIdAsync(model.UserId);
            user.DisplayName = model.DisplayName;
            user.Birthday = model.Birthday;

            var result = await _users.UpdateAsync(user);

            if (result.Succeeded)
            {
                _loggingService.Info(string.Format("用户{0}更新了UserId({1})资料", Site.CurrentUserName, model.UserId));
                return true;
            }
            else
            {
                _loggingService.Error(string.Format("用户{0}更新UserId[{1}]资料失败", Site.CurrentUserName, model.UserId));
                return false;
            }



        }