Beispiel #1
0
        public IActionResult UpdatePassword(UpdateInfoViewModel model)
        {
            model.UpdateStatus = -1;
            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var user   = _userManager.FindByIdAsync(userId);

            if (!String.IsNullOrEmpty(model.Password) &&
                !String.IsNullOrEmpty(model.ConfirmPassword) &&
                model.Password.Equals(model.ConfirmPassword))
            {
                try
                {
                    var result = _userManager.ChangePasswordAsync(user.Result, model.CurrentPassword, model.Password);
                    if (result.Result.Succeeded)
                    {
                        model.UpdateStatus = 0;
                    }
                }
                catch (Exception e)
                {
                    model.UpdateStatus = 1;
                }
            }

            return(View("MyProfile", model));
        }
Beispiel #2
0
        public ActionResult Index(string option, string userType)
        {
            if (option != null)
            {
                switch (option.ToLower())
                {
                case "updateinfo":
                {
                    _viewModel = new UpdateInfoViewModel();
                    CreateLayoutView("Cập nhật thông tin");
                    break;
                }

                case "updatepassword":
                {
                    _viewModel = new UpdatePasswordViewModel();
                    CreateLayoutView("Cập nhật mật khẩu");
                    break;
                }

                case "updatesetting":
                {
                    _viewModel = new UpdateSettingViewModel();
                    CreateLayoutView("Cài đặt");
                    break;
                }

                case "notification":
                {
                    _viewModel = new NotificationViewModel();
                    CreateLayoutView("Thông báo");
                    break;
                }

                case "requests":
                {
                    _viewModel = new RequestsViewModel();
                    CreateLayoutView("Lời mời kết bạn");
                    break;
                }

                default:
                {
                    _viewModel = new UpdateInfoViewModel();
                    CreateLayoutView("Cập nhật thông tin");
                    break;
                }
                }
            }
            else
            {
                _viewModel = new UpdateInfoViewModel();
                CreateLayoutView("Cập nhật thông tin");
            }
            ViewBag.newMember        = userType;
            ViewBag.listRequest      = _friendService.GetRelationship(User.Identity.GetUserId()).Count - 1;
            ViewBag.listNotification = _notificationService.getAllNotification(User.Identity.GetUserId()).Count - 1;

            return(View(_viewModel));
        }
Beispiel #3
0
        public ActionResult UpdateInfo()
        {
            _viewModel = new UpdateInfoViewModel();
            CreateLayoutView("Cập nhật thông tin");
            FieldHelper.CopyNotNullValue(UpdateInfoViewModel, _viewModel.User);
            ViewBag.listRequest      = _friendService.GetRelationship(User.Identity.GetUserId()).Count - 1;
            ViewBag.listNotification = _notificationService.getAllNotification(User.Identity.GetUserId()).Count - 1;

            return(PartialView("_UpdateInfo", UpdateInfoViewModel));
        }
Beispiel #4
0
        public IHttpActionResult UpdateInfo([FromBody] UpdateInfoViewModel request)
        {
            string username = Utilities.GetUserNameFromRequest(Request);

            if (username == null)
            {
                return(Unauthorized());
            }
            User user = ApplicationUserManager.FindByName(username);

            if (user == null)
            {
                return(BadRequest("Get user Error"));
            }

            try
            {
                if (request.Image != null && request.Image.Trim().Length != 0)
                {
                    string fileName = user.Id + DateTime.Now.Millisecond.ToString() + ".jpg";
                    string filePath = HttpContext.Current.Server.MapPath("~/Media/UserImage/") + fileName;
                    Utilities.ConvertFromBitmap(request.Image).Save(filePath);
                    user.ImageUrl = "/Media/UserImage/" + fileName;
                }
                user.LastName    = request.Lastname;
                user.FirstName   = request.Bio;
                user.PhoneNumber = request.Phone;
                user.TKNL        = request.Tknl;
                user.Address     = request.Address + "_" + request.GeoId;

                var result = ApplicationUserManager.Update(user);
                userService.SaveUser();
                if (!result.Succeeded)
                {
                    return(BadRequest("Update error"));
                }
            }
            catch (Exception)
            {
                return(BadRequest("Error"));
            }

            request.Status_code = "200";
            request.Message     = "OK";
            request.Image       = user.ImageUrl;
            City city = cityService.GetCities().FirstOrDefault(c => c.Code.Equals(request.GeoId));

            if (city != null)
            {
                request.Address = request.Address + ", " + city.Name + ", " + city.Country.Name;
            }

            return(Ok(request));
        }
Beispiel #5
0
        public async Task <UserDto> UpdateUserAsync(UpdateInfoViewModel user, string username)
        {
            User match = await _userManager.FindByNameAsync(username);

            match.Avatar          = string.IsNullOrEmpty(user.Avatar) ? match.Avatar : user.Avatar;
            match.FirstName       = string.IsNullOrEmpty(user.FirstName) ? match.FirstName : user.FirstName;
            match.LastName        = string.IsNullOrEmpty(user.LastName) ? match.LastName : user.LastName;
            match.Email           = string.IsNullOrEmpty(user.Email) ? match.Email : user.Email;
            match.NormalizedEmail = string.IsNullOrEmpty(user.Email) ? match.NormalizedEmail : user.Email.ToUpper();
            if (await _unitOfWork.CompleteAsync() > 0)
            {
                return(_mapper.Map <UserDto>(match));
            }
            return(null);
        }
Beispiel #6
0
        public async Task <ActionResult> UpdateUserInformation(UpdateInfoViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                user.AddressCity    = model.AddressCity;
                user.AddressState   = model.AddressState;
                user.AddressStreet  = model.AddressStreet;
                user.AddressZipcode = model.AddressZipcode;
                user.Email          = model.Email;
                user.FirstName      = model.FirstName;
                user.LastName       = model.LastName;
                await UserManager.UpdateAsync(user);
            }

            // If we got this far, something failed, redisplay form
            return(RedirectToAction("Index", "Manage")); //View(model);
        }
Beispiel #7
0
        public async Task <IActionResult> UpdateUserInfoAsync(UpdateInfoViewModel update)
        {
            if (ModelState.IsValid)
            {
                if (update.UserImage != null)
                {
                    UserDto user = await _userService.FindUserAsync(User.Identity.Name);
                    await DeleteFileAsync(user.Avatar);

                    update.Avatar = await UploadFileAsync(update.UserImage);
                }
                UserDto result = await _userService.UpdateUserAsync(update, User.Identity.Name);

                if (result != null)
                {
                    return(Json(new { message = "Your info was updated successfully", user = result }));
                }
            }

            return(Json(new { message = "Update wasn't successful" }));
        }
Beispiel #8
0
        public JsonResult UpdateInfo(UpdateInfoViewModel model, string userType)
        {
            if (ModelState.IsValid)
            {
                var user = _service.GetUserById(User.Identity.GetUserId());
                FieldHelper.CopyNotNullValue(user, model);

                _applicationUserService.Update(user);
                try
                {
                    _applicationUserService.Save();
                    ViewBag.newMember        = userType;
                    ViewBag.listRequest      = _friendService.GetRelationship(User.Identity.GetUserId()).Count - 1;
                    ViewBag.listNotification = _notificationService.getAllNotification(User.Identity.GetUserId()).Count - 1;

                    return(Json(new
                    {
                        result = "success"
                    }));
                }
                catch (Exception e)
                {
                    return(Json(new
                    {
                        result = "failed",
                    }));
                }
            }
            else
            {
                return(Json(new
                {
                    result = "failed",
                    data = ModelState.Select(x => new { Field = x.Key, Error = x.Value.Errors }).ToList()
                }));
            }
        }
Beispiel #9
0
        public IActionResult UpdateInfo(UpdateInfoViewModel model)
        {
            // no error initially
            model.UpdateStatus = -1;
            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var user   = _userManager.FindByIdAsync(userId);

            // try updating the database
            try
            {
                UserAddressModel address = _userAddressContext.UserAddress.Select(addrs => addrs).Where(add => add.Id.Equals(userId)).FirstOrDefault();
                UserInfoModel    info    = _userInfoContext.UserInfo.Select(infos => infos).Where(info => info.Id.Equals(userId)).FirstOrDefault();

                address.StreetAddress  = model.StreetAddress;
                address.StreetAddress2 = model.StreetAddress2;
                address.City           = model.City;
                address.State          = model.State;
                address.Zip            = model.Zip;

                info.OrganizationName = model.OrganizationName;
                info.FirstName        = model.FirstName;
                info.LastName         = model.LastName;
                info.PhoneNumber      = model.PhoneNumber;
                info.TaxID            = model.TaxID;

                _userAddressContext.SaveChanges();
                _userInfoContext.SaveChanges();

                model.UpdateStatus = 0;
            }
            catch (Exception e)
            {
                model.UpdateStatus = 1;
            }

            return(View("MyProfile", model));
        }
        public async Task <bool> UpdateInfo(UpdateInfoViewModel model)
        {
            try
            {
                var user = await UserManager.FindByIdAsync(model.UserId);

                if (user == null)
                {
                    return(false);
                }

                user.Email = model.Email;

                var result = await UserManager.UpdateAsync(user);

                if (!result.Succeeded)
                {
                    return(false);
                }
                else
                {
                    var UserN = db.C_User.FirstOrDefault(s => s.UserId.Equals(model.UserId)).UserName.Substring(0, 6);
                    var UserR = db.C_User.FirstOrDefault(s => s.UserId.Equals(model.UserId)).UserName.Substring(6, 3);

                    db.supplierregions.FirstOrDefault(s => s.sid.Equals(UserN) && s.region.Equals(UserR)).mobile = model.Mobile;

                    db.SaveChanges();

                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
Beispiel #11
0
        public IActionResult MyProfile()
        {
            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            UserAddressModel address = _userAddressContext.UserAddress.Select(addrs => addrs).Where(add => add.Id.Equals(userId)).FirstOrDefault();
            UserInfoModel    info    = _userInfoContext.UserInfo.Select(infos => infos).Where(info => info.Id.Equals(userId)).FirstOrDefault();

            UpdateInfoViewModel model = new UpdateInfoViewModel
            {
                OrganizationName = info.OrganizationName,
                FirstName        = info.FirstName,
                LastName         = info.LastName,
                PhoneNumber      = info.PhoneNumber,
                StreetAddress    = address.StreetAddress,
                StreetAddress2   = address.StreetAddress2,
                City             = address.City,
                State            = address.State,
                Zip   = address.Zip,
                TaxID = info.TaxID
            };

            // no error initially
            model.UpdateStatus = -1;
            return(View(model));
        }
Beispiel #12
0
 public IActionResult UpdateInfo([FromRoute] long id, [FromBody] UpdateInfoViewModel updateInfoViewModel)
 {
     return(NoContent());
 }