public ActionResult UpdateEmailDB(UpdateEmailViewModel user)
        {
            if (!ModelState.IsValid)
            {
                return(View("UpdateEmail", user));
            }

            int id = (int)Session["User"];

            _context.NWUsers.SingleOrDefault(x => x.Id.Equals(id)).Email = user.Email;
            _context.SaveChanges();

            return(RedirectToAction("ViewUserData"));

            //if (db.UpdateEmail((int)Session["User"], user.Email))
            //{
            //    ViewBag.Error = null;
            //    return RedirectToAction("ViewUserData");
            //}
            //else
            //{
            //    ViewBag.Error = "Adatbázis hiba történt!";
            //    return View("ViewUserData");
            //}
        }
        public PartialViewResult UpdateDetails(bool isPartial = false)
        {
            int id = (int)Session["id"];
            UpdateEmailViewModel emailModel = dbcon.getUserEmail(id);

            return(isPartial ? PartialView("_UpdateDetails") : PartialView());
        }
示例#3
0
        public async Task <ActionResult> UpdateEmail(UpdateEmailViewModel model)
        {
            if (ModelState.IsValid)
            {
                // get user object from the storage
                var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                var result = await UserManager.CheckPasswordAsync(user, model.Password);

                if (result)
                {
                    // change username and email

                    // Persiste the changes

                    bool emailExists = false;
                    foreach (var u in UserManager.Users)
                    {
                        if (u.Email == model.NewEmail && u.EmailConfirmed)
                        {
                            emailExists = true;

                            break;
                        }
                    }
                    if (emailExists)
                    {
                        return(View("ChangeEmailError"));
                    }

                    // generage email confirmation code

                    var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                    if (Request.Url != null)
                    {
                        var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code, email = model.NewEmail }, protocol: Request.Url.Scheme);

                        await _identityMessageService.SendAsync(new IdentityMessage
                        {
                            Body = "Вы предоставили новый email-адрес для вашей" +
                                   " учётной записи Для смены адреса вам необходимо его активировать, щелкнув <a href=\"" + callbackUrl + "\">здесь</a>",
                            Subject     = "Подтверждение почты",
                            Destination = model.NewEmail
                        });
                    }

                    return(View("UpdateEmailRequest"));
                }
                return(View("ChangeEmailError"));
            }
            return(View("ChangeEmailError"));

            // send email to the user with the confirmation link
        }
示例#4
0
 public async Task <IActionResult> UpdateFiles(string id, [FromForm] UpdateEmailViewModel request)
 {
     try
     {
         var response = _manager.UpdateFiles(id, request);
         return(Ok(response));
     }
     catch (Exception ex)
     {
         return(ex.GetActionResult());
     }
 }
        public EmailViewModel UpdateFiles(string id, UpdateEmailViewModel request)
        {
            var email = _emailRepository.GetOne(Guid.Parse(id));

            if (email == null)
            {
                throw new EntityDoesNotExistException("Email could not be found or does not exist");
            }

            email.ConversationId  = request.ConversationId;
            email.Direction       = request.Direction;
            email.EmailObjectJson = request.EmailObjectJson;
            email.SenderAddress   = request.SenderAddress;
            email.SenderName      = request.SenderName;
            email.SenderUserId    = _applicationUser?.PersonId;
            email.Status          = request.Status;
            email.EmailAccountId  = request.EmailAccountId;
            email.ReplyToEmailId  = request.ReplyToEmailId;
            email.Reason          = request.Reason;
            email.SentOnUTC       = request.SentOnUTC;

            //if files don't exist in file manager: add file entity, upload file, and add email attachment attachment entity
            var attachments = _emailAttachmentRepository.Find(null, q => q.EmailId == Guid.Parse(id))?.Items;

            if (string.IsNullOrEmpty(request.DriveId))
            {
                var fileToCheck = _storageFileRepository.GetOne(attachments[0].Id.Value);
                var drive       = _storageDriveRepository.GetOne(fileToCheck.StorageDriveId.Value);
                request.DriveId = drive.Id.ToString();
            }

            string hash = string.Empty;

            IFormFile[] filesArray       = CheckFiles(request.Files, hash, attachments, request.DriveId);
            var         emailAttachments = AddAttachments(filesArray, email.Id.Value, request.DriveId);

            //update email
            _emailRepository.Update(email);

            attachments = _emailAttachmentRepository.Find(null, q => q.EmailId == Guid.Parse(id))?.Items;
            EmailViewModel response = GetEmailViewModel(email, attachments);

            if (attachments.Count == 0 || attachments == null)
            {
                response.Attachments = emailAttachments;
            }

            return(response);
        }
示例#6
0
        public UpdateEmailViewModel getUserEmail(int id)
        {
            UpdateEmailViewModel emailModel = new UpdateEmailViewModel();

            OpenConnection();

            MySqlCommand cmdAlbums = new MySqlCommand("SELECT email FROM users Where id = @id ", con);

            cmdAlbums.Parameters.AddWithValue("@id", id);

            using (reader = cmdAlbums.ExecuteReader())
            {
                while (reader.Read())
                {
                    emailModel.email = reader.GetString("email");
                }
            }
            CloseConnection();
            return(emailModel);
        }
示例#7
0
        public async Task <IActionResult> UpdateFiles(string id, [FromForm] UpdateEmailViewModel request)
        {
            var email = repository.GetOne(Guid.Parse(id));

            if (email == null)
            {
                return(NotFound());
            }

            email.ConversationId  = request.ConversationId;
            email.Direction       = request.Direction;
            email.EmailObjectJson = request.EmailObjectJson;
            email.SenderAddress   = request.SenderAddress;
            email.SenderName      = request.SenderName;
            email.SenderUserId    = applicationUser?.PersonId;
            email.Status          = request.Status;
            email.EmailAccountId  = request.EmailAccountId;
            email.ReplyToEmailId  = request.ReplyToEmailId;
            email.Reason          = request.Reason;
            email.SentOnUTC       = request.SentOnUTC;

            //if files don't exist in binary objects: add binary object entity, upload file, and add email attachment attachment entity
            var    attachments = emailAttachmentRepository.Find(null, q => q.EmailId == Guid.Parse(id))?.Items;
            string hash        = string.Empty;

            IFormFile[] filesArray       = manager.CheckFiles(request.Files, (Guid)email.Id, hash, attachments);
            var         emailAttachments = manager.AddAttachments(filesArray, (Guid)email.Id, hash);

            //update email
            repository.Update(email);

            attachments = emailAttachmentRepository.Find(null, q => q.EmailId == Guid.Parse(id))?.Items;
            EmailViewModel response = manager.GetEmailViewModel(email, attachments);

            if (attachments.Count == 0 || attachments == null)
            {
                response.Attachments = emailAttachments;
            }
            return(Ok(response));
        }
示例#8
0
        public async Task <IActionResult> UpdateEmail(UpdateEmailViewModel seller, string id)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    string flag = "";
                    HttpContext.Request.Cookies.TryGetValue("CurrentUser", out flag);
                    if (string.IsNullOrEmpty(flag))
                    {
                        return(RedirectToAction(nameof(SellerController.Login), "Seller"));
                    }
                    else
                    {
                        Seller cur = JsonConvert.DeserializeObject <Seller>(flag);
                        Seller ss  = this._context.Sellers.First <Seller>(t => t.Id == cur.Id);
                        ss.Email = seller.Email;
                        var result = await this._context.SaveChangesAsync();

                        cur.Email = seller.Email;
                        string currentUser = JsonConvert.SerializeObject(cur);
                        HttpContext.Response.Cookies.Append("CurrentUser", currentUser);
                        return(RedirectToAction(nameof(SellerController.Profile), "Seller"));
                    }
                }
                catch (Exception ex)
                {
                    HttpContext.Response.Cookies.Append("IsSuccess", "false");
                    HttpContext.Response.Cookies.Append("Messages", ex.Message);
                    HttpContext.Response.Cookies.Append("IsRegister", "false");
                    HttpContext.Response.Cookies.Append("Info", "Woops, Update Email Failed!");
                    return(RedirectToAction(nameof(SellerController.Result), "Seller"));
                }
            }
            return(View());
        }