Example #1
0
        public IActionResult UpdateDOB(User user)
        {
            User            currentUser = authProvider.GetCurrentUser();
            UpdateProfileVM updateUser  = profileDAL.UpdateDOB(user.DOB, currentUser.Id);

            return(View("UpdateProfile", updateUser));
        }
Example #2
0
        /// <summary>
        /// Updates user's home state after creation
        /// </summary>
        /// <param name="state">The new state</param>
        /// <param name="id">The user's id</param>
        /// <returns>Updated profile information model</returns>
        public UpdateProfileVM UpdateState(string state, int id)
        {
            UpdateProfileVM user = new UpdateProfileVM();

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();
                    string     sql = $"UPDATE users SET state = @state where id = @id; SELECT * FROM users where id = @id";
                    SqlCommand cmd = new SqlCommand(sql, conn);
                    cmd.Parameters.AddWithValue("@state", state);
                    cmd.Parameters.AddWithValue("@id", id);
                    cmd.ExecuteNonQuery();

                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        user.Username = Convert.ToString(reader["username"]);
                        user.Password = Convert.ToString(reader["password"]);
                        user.Name     = Convert.ToString(reader["name"]);
                        user.State    = Convert.ToString(reader["state"]);
                        user.DOB      = Convert.ToDateTime(reader["DOB"].ToString());
                    }
                }
            }
            catch (SqlException)
            {
                throw;
            }
            return(user);
        }
        //GET: /Manage/UpdateProfile
        public ActionResult UpdateProfile()
        {
            var user  = db.Users.Find(User.Identity.GetUserId());
            var model = new UpdateProfileVM(user);

            return(View(model));
        }
Example #4
0
        private async Task <string> UpdateCustomer(UpdateProfileVM model, UserIdentity user)
        {
            string accessToken = Request.Headers[HeaderNames.Authorization];

            var apiClient = new HttpClient();

            apiClient.DefaultRequestHeaders.Add("Authorization", accessToken);

            var body = new
            {
                AccountId = user.Id,
                model.Fullname,
                model.ShopName,
                model.ShopAddress,
                model.AreaId,
                model.LocationOnMap
            };

            var json = JsonConvert.SerializeObject(body);
            var data = new StringContent(json, Encoding.UTF8, "application/json");

            var url = _configuration["BrimoAPIURL"] + "/api/CustomerManagment/Customers";

            var response = await apiClient.PutAsync(url, data);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new Exception(await response.Content.ReadAsStringAsync());
            }

            var responseString = await response.Content.ReadAsStringAsync();

            return(responseString);
        }
Example #5
0
        public async Task <IActionResult> UpdateProfile(UpdateProfileVM model)
        {
            var userId = User?.FindFirstValue(ClaimTypes.NameIdentifier);
            var user   = await _userManager.Users.FirstOrDefaultAsync(x => x.Id == userId);

            if (user == null)
            {
                throw new UserNotFoundException(model.PhoneNumber);
            }

            if (!user.PhoneNumberConfirmed)
            {
                throw new PhoneNumberNotConfirmedException(model.PhoneNumber);
            }

            if (!string.IsNullOrEmpty(model.Fullname))
            {
                user.FullName = model.Fullname;
                await _userManager.UpdateAsync(user);
            }

            await UpdateCustomer(model, user);

            return(Ok());
        }
Example #6
0
        public ActionResult UpdateProfile(UpdateProfileVM model)
        {
            var user = db.Users.Find(User.Identity.GetUserId());

            user.FirstName = model.FirstName;
            user.LastName  = model.LastName;
            db.SaveChanges();
            return(RedirectToAction("Index", "Home", new { Message = ManageMessageId.ChangeInfoSuccess }));
        }
        public async Task <IActionResult> EditProfile(UpdateProfileVM updateProfileVM)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", "Zəhmət olmasa mobil operatorunuzu Daxil Edin");
                ViewBag.Operators = _context.Operators;
                return(View(updateProfileVM));
            }
            ApplicationUser applicationUser = await _userManager.FindByNameAsync(User.Identity.Name);

            applicationUser.Firstname   = updateProfileVM.applicationUser.Firstname;
            applicationUser.Lastname    = updateProfileVM.applicationUser.Lastname;
            applicationUser.UserName    = updateProfileVM.applicationUser.UserName;
            applicationUser.OperatorId  = updateProfileVM.OperatorId;
            applicationUser.PhoneNumber = updateProfileVM.applicationUser.PhoneNumber;

            if (updateProfileVM.applicationUser.Email != applicationUser.Email)
            {
                applicationUser.Email          = updateProfileVM.applicationUser.Email;
                applicationUser.EmailConfirmed = false;
                SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
                client.UseDefaultCredentials = false;
                client.EnableSsl             = true;
                client.Credentials           = new NetworkCredential(_configuration["ConnectionsStrings:SmtpClientCredentialEmail"], _configuration["ConnectionsStrings:SmtpClientCredentialPassword"]);
                MailMessage message = new MailMessage("*****@*****.**", updateProfileVM.applicationUser.Email);
                message.IsBodyHtml = true;
                message.Subject    = "Hesabın təsdiqlənməsi";
                message.Body       = $"<a href='http://power123elec-001-site1.ctempurl.com/Account/EmailVerify?id={updateProfileVM.applicationUser.Id}'>Xahiş edirik hesabınızı təsdiqləyəsiniz</a>";
                await client.SendMailAsync(message);
            }
            if (updateProfileVM.Photo == null)
            {
                applicationUser.PhotoUrl = "noImage.png";
            }
            else if (updateProfileVM.Photo.ContentType.Contains("image/"))
            {
                string folderPath = Path.Combine(_env.WebRootPath, "userImages");
                string fileName   = Guid.NewGuid().ToString() + "_" + updateProfileVM.Photo.FileName;
                string filePath   = Path.Combine(folderPath, fileName);
                applicationUser.PhotoUrl = fileName;

                using (FileStream fileStream = new FileStream(filePath, FileMode.Create))
                {
                    await updateProfileVM.Photo.CopyToAsync(fileStream);
                }
            }
            if (updateProfileVM.NewPassword != null)
            {
                await _userManager.ChangePasswordAsync(applicationUser, updateProfileVM.СurrentPassword, updateProfileVM.NewPassword);
            }

            _context.SaveChanges();
            return(RedirectToAction("UserProfile", "Account"));
        }
        public async Task <ActionResult> UpdateProfile(UpdateProfileVM model)
        {
            var user = db.Users.Find(model.Id);

            user.FirstName = model.FirstName;
            user.LastName  = model.LastName;
            db.SaveChanges();

            await AuthorizeExtensions.RefreshAuthentication(HttpContext, user);

            return(RedirectToAction("UpdateProfile"));
        }
Example #9
0
        public async Task <IActionResult> MyProfile()
        {
            var user = await _userDataService.GetUser(User.UserId());

            if (user != null)
            {
                var vm = new UpdateProfileVM()
                {
                    Email       = user.Email,
                    FirstName   = user.FirstName,
                    LastName    = user.LastName,
                    PhoneNumber = user.PhoneNumber
                };
                return(View(vm));
            }
            return(View(new UpdateProfileVM()));
        }
Example #10
0
        public IActionResult UpdateProfile()
        {
            User user = new User();

            user = authProvider.GetCurrentUser();

            UpdateProfileVM vm = new UpdateProfileVM
            {
                Id       = user.Id,
                Username = user.Username,
                Name     = user.Name,
                State    = user.State,
                DOB      = user.DOB
            };

            return(View(vm));
        }
        public async Task <IActionResult> EditProfile()
        {
            ViewBag.Operators = _context.Operators;

            ApplicationUser loggedUser = await _userManager.FindByNameAsync(User.Identity.Name);

            UpdateProfileVM updateProfileVM = new UpdateProfileVM()
            {
                applicationUser = loggedUser,
            };

            if (updateProfileVM == null)
            {
                return(RedirectToAction("Error", "Home"));
            }

            return(View(updateProfileVM));
        }
Example #12
0
        public ActionResult UpdateProfile(UpdateProfileVM data, HttpPostedFileBase pic)
        {
            try
            {
                var cus = db.Customers.Find(int.Parse(User.Identity.Name));
                data.Id     = cus.Id;
                data.Avatar = cus.Avatar;

                if (pic != null)
                {
                    string filename = DateTime.Now.Ticks + "_" + pic.FileName.Split('/').Last();

                    string path = Server.MapPath("~/Uploads/Avatars") + "\\" + data.Id;
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }

                    if (System.IO.File.Exists(path + "\\" + data.Avatar))
                    {
                        System.IO.File.Delete(path + "\\" + data.Avatar);
                    }

                    pic.SaveAs(path + "\\" + filename);
                    data.Avatar = filename;
                }


                AutoMapper.Mapper.Map(data, cus);


                db.SaveChanges();



                ViewBag.Message = "Update Successfully";
            }
            catch (Exception ex)
            {
                ViewBag.Message = ex.Message;
            }
            return(View(data));
        }
Example #13
0
        public async Task <IActionResult> MyProfile(UpdateProfileVM model)
        {
            if (string.IsNullOrWhiteSpace(model.FirstName) || string.IsNullOrWhiteSpace(model.LastName) || string.IsNullOrWhiteSpace(model.Email))
            {
                return(View(model));
            }

            var user = await _userDataService.GetUser(User.UserId());

            var request = new UpdateUserRequestModel()
            {
                UserId      = User.UserId(),
                FirstName   = model.FirstName,
                LastName    = model.LastName,
                Email       = model.Email,
                PhoneNumber = model.PhoneNumber
            };

            user = await _userDataService.UpdateUser(request);

            if (model.NewPassword != null)
            {
                var updatePasswordRequest = new UpdateUserPasswordRequestModel()
                {
                    UserId      = user.Id,
                    NewPassword = model.NewPassword
                };
                var success = await _userDataService.UpdateUserPassword(updatePasswordRequest);
            }

            await HttpContext.Authentication.SignOutAsync();

            await LogUserIn(user, false);

            return(View());
        }
Example #14
0
        public IActionResult UpdatePassword(UpdateProfileVM user)
        {
            bool val = authProvider.ChangePassword(user.CurrentPassword, user.Password);

            if (val)
            {
                TempData["message"] = "Password succesfully changed";

                User var2 = new User();
                var2 = authProvider.GetCurrentUser();

                UpdateProfileVM vm2 = new UpdateProfileVM();
                vm2.Id       = var2.Id;
                vm2.Username = var2.Username;
                vm2.Name     = var2.Name;
                vm2.State    = var2.State;
                vm2.DOB      = var2.DOB;

                return(View("UpdateProfile", vm2));
            }
            TempData["message2"] = "Please enter your current password";

            User var = new User();

            var = authProvider.GetCurrentUser();

            UpdateProfileVM vm = new UpdateProfileVM();

            vm.Id       = var.Id;
            vm.Username = var.Username;
            vm.Name     = var.Name;
            vm.State    = var.State;
            vm.DOB      = var.DOB;

            return(View("UpdateProfile", vm));
        }