Beispiel #1
0
        public async Task <PartialViewResult> EmailDetails(string messageId)
        {
            GraphHelper  graphHelper = new GraphHelper();
            EmailMessage message     = await graphHelper.GetEmailMessage(messageId);

            EmailDetailsViewModel model = new EmailDetailsViewModel();

            model.EmailMessage = message;

            model.HelpdeskOperators = await graphHelper.GetHelpdeskOperators();

            return(PartialView("_EmailDetails", model));
        }
Beispiel #2
0
        public ActionResult ViewProviderAnswer(long id)
        {
            var userOrg = this.userService.GetById(this.User.Identity.GetUserId()).Site.Organisation;

            try
            {
                //Create imap clien
                var client = new ImapClient();

                client.Port        = 993;
                client.SslProtocol = SslProtocols.Default;
                client.Host        = "imap-mail.outlook.com";
                client.ValidateServerCertificate = true;
                client.UseSsl = true;

                var viewModel = new EmailDetailsViewModel();
                viewModel.Request = new AddProviderToRequestViewModel();
                viewModel.Items   = new AddItemsFromRequest();

                //Add request offers to viewmodel
                viewModel.Request.Offers = new List <ProviderOfferViewModel>
                {
                    new ProviderOfferViewModel
                    {
                        Price    = 1,
                        Quantity = 1,
                        Currency = this.currencyService.GetAll()
                                   .Where(x => x.OrganisationId == userOrg.Id)
                                   .ToList()
                                   .ConvertAll(x =>
                                               new CurrencyViewModel
                        {
                            Code = x.Code,
                            Id   = x.Id,
                        }).ToList()
                    }
                };

                //Add items to viewmodel
                viewModel.Items.Items = new List <AddItemViewModel> {
                    new AddItemViewModel {
                        Organisations = new List <OrganisationViewModel> {
                            new OrganisationViewModel
                            {
                                Id   = userOrg.Id,
                                Name = userOrg.Name
                            }
                        },
                        Price    = 1,
                        Quantity = 1,
                        Currency = this.currencyService.GetAll()
                                   .Where(x => x.OrganisationId == userOrg.Id)
                                   .ToList()
                                   .ConvertAll(x =>
                                               new CurrencyViewModel
                        {
                            Code = x.Code,
                            Id   = x.Id,
                        }).ToList()
                    }
                };

                //Connect
                if (client.Connect())
                {
                    var organisation = this.organisationService.GetById(
                        this.userService.GetUserOrganisationId(this.User.Identity.GetUserId()));

                    var sentFrom = organisation.EmailClient;
                    var pwd      = KAssets.Controllers.StaticFunctions.RSAALg.Decryption(organisation.EmailClientPassword);

                    //Login
                    if (client.Login(sentFrom, pwd))
                    {
                        //Download the messages
                        client.Folders.Inbox.Messages.Download();

                        //Select the message
                        MessageCollection messages = client.Folders.Inbox.Messages;
                        var message = messages.Where(x => x.UId == id).First();

                        message.Seen = true;

                        message.Body.Download();
                        viewModel.Content    = message.Body.Html;
                        viewModel.DateOfSend = message.Date.ToString();
                        viewModel.From       = message.From.Address;
                        viewModel.Subject    = message.Subject;
                        viewModel.To         = message.To.First().Address;
                        viewModel.UId        = id;

                        viewModel.Request.ProviderEmail = message.From.Address;
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Connection Failed. Please refresh !");
                }
                client.Disconnect();

                //Add ofers to viewmodel
                if (TempData["Values"] != null)
                {
                    viewModel.Request.Offers = new List <ProviderOfferViewModel>();
                    var keys = JsonConvert.DeserializeObject <List <ProviderOfferViewModel> >(TempData["Values"].ToString());
                    for (int i = 0; i < keys.Count; i++)
                    {
                        viewModel.Request.Offers.Add(keys[i]);
                        viewModel.Request.Offers[i].Currency = this.currencyService.GetAll()
                                                               .Where(x => x.OrganisationId == userOrg.Id)
                                                               .ToList()
                                                               .ConvertAll(x =>
                                                                           new CurrencyViewModel
                        {
                            Code = x.Code,
                            Id   = x.Id,
                        }).ToList();
                    }
                }

                //Add items to viewmodel
                if (TempData["ValuesItems"] != null)
                {
                    viewModel.Items.Items = new List <AddItemViewModel>();
                    var keys = JsonConvert.DeserializeObject <List <AddItemViewModel> >(TempData["ValuesItems"].ToString());
                    for (int i = 0; i < keys.Count; i++)
                    {
                        keys[i].Organisations = new List <OrganisationViewModel> {
                            new OrganisationViewModel
                            {
                                Id   = userOrg.Id,
                                Name = userOrg.Name
                            }
                        };
                        viewModel.Items.Items.Add(keys[i]);
                        viewModel.Items.Items[i].Currency = this.currencyService.GetAll()
                                                            .Where(x => x.OrganisationId == userOrg.Id)
                                                            .ToList()
                                                            .ConvertAll(x =>
                                                                        new CurrencyViewModel
                        {
                            Code = x.Code,
                            Id   = x.Id,
                        }).ToList();
                    }
                }

                //Add model errors to ModelState
                if (TempData["Keys"] != null)
                {
                    var keys = JsonConvert.DeserializeObject <Dictionary <string, string[]> >(TempData["Keys"].ToString());
                    for (int i = 0; i < keys.Count; i++)
                    {
                        foreach (var item in keys.ElementAt(i).Value)
                        {
                            this.ModelState.AddModelError(keys.ElementAt(i).Key, item);
                        }
                    }
                }

                TempData["Keys"]   = null;
                TempData["Values"] = null;
                return(View(viewModel));
            }
            catch
            {
                return(Redirect("/Orders/ProviderOrder/ViewProviderAnswer/" + id));
            }
        }