Exemplo n.º 1
0
        public ActionResult ViewApprovedRequest(int id)
        {
            var request = this.requestToProviderService.GetById(id);

            //Verify if request is from user organisation
            if (!this.IsMegaAdmin())
            {
                if (request.From.Site.OrganisationId != this.userService.GetUserOrganisationId(this.User.Identity.GetUserId()))
                {
                    return(Redirect("/Home/NotAuthorized"));
                }
            }

            //Create email for provider
            var sentEmail = "";

            foreach (var item in request.SendOffers.Where(x => x.IsApproved))
            {
                sentEmail += " " + "Brand: " + item.Brand + "<br/>   Model: " + item.Model + "<br/>   Producer: " +
                             item.Producer + "<br/>    Price: " + item.Price.Value + " " + item.Price.Currency.Code + "<br/>   Quantity: " + item.Quantity + "<br/>  <br/>  ";
            }

            //Set viewmodel data
            var viewModel = new RequestToProviderFullViewModel
            {
                DateOfSend = request.DateOfSend.ToString(),
                FromName   = (request.From.FirstName != null) ?
                             request.From.FirstName + " " + request.From.SecondName + " " + request.From.LastName :
                             request.From.Email,
                ProviderEmail = request.Provider.Email,
                Offers        = request.SendOffers.ToList().ConvertAll(x => new ProviderOfferViewModel
                {
                    Brand           = x.Brand,
                    ItemModel       = x.Model,
                    Price           = x.Price.Value,
                    Producer        = x.Producer,
                    Quantity        = x.Quantity,
                    IsSelected      = x.IsApproved,
                    CurrencyNotaion = x.Price.Currency.Code
                }),
                WantItems = request.WantItems.ToList().ConvertAll(x => new ProviderOfferViewModel
                {
                    Brand           = x.Brand,
                    ItemModel       = x.Model,
                    Price           = x.Price.Value,
                    Producer        = x.Producer,
                    Quantity        = request.CountItems.Where(y => y.Key == x.Id).FirstOrDefault().Want,
                    CurrencyNotaion = x.Price.Currency.Code
                }),
                Id        = id,
                SentEmail = sentEmail
            };

            return(View(viewModel));
        }
Exemplo n.º 2
0
        public ActionResult ApproveRequest(RequestToProviderFullViewModel model)
        {
            var request = this.requestToProviderService.GetById(model.Id);

            //Verify if request is from user organisation
            if (!this.IsMegaAdmin())
            {
                if (request.From.Site.OrganisationId != this.userService.GetUserOrganisationId(this.User.Identity.GetUserId()))
                {
                    return(Redirect("/Home/NotAuthorized"));
                }
            }

            //Set request is approved
            this.requestToProviderService.SetApproved(model.Id);

            //Set request is seen by approved
            this.requestToProviderService.SetIsSeenByApproved(model.Id);

            //Add approved offers to request
            var ids = model.Offers.Where(x => x.IsSelected == true).Select(x => x.Id).ToList();

            this.requestToProviderService.SetApprovedOffer(model.Id, ids);


            var organisation = this.organisationService.GetById(
                this.userService.GetUserOrganisationId(this.User.Identity.GetUserId()));

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

            // Configure the client:
            System.Net.Mail.SmtpClient client =
                new System.Net.Mail.SmtpClient("smtp-mail.outlook.com");

            client.Port                  = 587;
            client.DeliveryMethod        = System.Net.Mail.SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;

            // Creatte the credentials:
            System.Net.NetworkCredential credentials =
                new System.Net.NetworkCredential(credentialUserName, pwd);

            client.EnableSsl   = true;
            client.Credentials = credentials;

            // Create the message:
            var to   = request.Provider.Email;
            var mail =
                new System.Net.Mail.MailMessage(sentFrom, to);

            request = this.requestToProviderService.GetById(model.Id);

            mail.Subject = "The company wants: ";

            var body = "Order id: " + model.Id;

            foreach (var item in request.SendOffers.Where(x => x.IsApproved))
            {
                body += " " + "Brand: " + item.Brand + "\r\n Model: " + item.Model + "\r\n Producer: " +
                        item.Producer + "\r\n  Price: " + item.Price.Value + " " + item.Price.Currency.Code + "\r\n Quantity: " + item.Quantity + "\r\n \r\n";
            }
            mail.Body = body;
            // Send:
            client.Send(mail);

            //Add event that request is approved
            var aEvent = new KAssets.Models.Event
            {
                UserId             = request.FromId,
                Content            = "Your request to provider was approved. ",
                Date               = DateTime.Now,
                EventRelocationUrl = "/Orders/ProviderOrder/GetApprovedRequests"
            };

            this.eventService.Add(aEvent);

            return(Redirect("/Orders/ProviderOrder/GetRequestsForApproving"));
        }
Exemplo n.º 3
0
        public ActionResult ViewRequestForApproving(int id)
        {
            var request = this.requestToProviderService.GetById(id);

            //Verify if request is from user organisation
            if (!this.IsMegaAdmin())
            {
                if (request.From.Site.OrganisationId != this.userService.GetUserOrganisationId(this.User.Identity.GetUserId()))
                {
                    return(Redirect("/Home/NotAuthorized"));
                }
            }

            //Add request data to viewmodel
            var viewModel = new RequestToProviderFullViewModel
            {
                DateOfSend = request.DateOfSend.ToString(),
                FromName   = (request.From.FirstName != null) ?
                             request.From.FirstName + " " + request.From.SecondName + " " + request.From.LastName :
                             request.From.Email,
                ProviderEmail = request.Provider.Email,
                Offers        = request.SendOffers.ToList().ConvertAll(x => new ProviderOfferViewModel
                {
                    Brand           = x.Brand,
                    ItemModel       = x.Model,
                    Price           = x.Price.Value,
                    Producer        = x.Producer,
                    Quantity        = x.Quantity,
                    CurrencyNotaion = x.Price.Currency.Code,
                    Id = x.Id
                }),
                Id = id
            };

            viewModel.Offers.OrderBy(x => x.Brand).OrderBy(x => x.ItemModel).OrderBy(x => x.Producer);

            var baseCurrencyId = this.currencyService.GetAll().First().Id;

            //Select the the best offers
            foreach (var item in viewModel.Offers)
            {
                int flag = 0;
                foreach (var item2 in viewModel.Offers)
                {
                    if (item2.ItemModel.Trim().ToLower() == item.ItemModel.Trim().ToLower() &&
                        item2.Brand.Trim().ToLower() == item.Brand.Trim().ToLower())
                    {
                        var price2 = this.exchangeService.GetRateNotation(baseCurrencyId, item2.CurrencyNotaion) * item2.Price;
                        var price  = this.exchangeService.GetRateNotation(baseCurrencyId, item.CurrencyNotaion) * item.Price;

                        if (price2 < price)
                        {
                            item2.IsSelected = true;
                            item.IsSelected  = false;
                        }
                        flag++;
                    }
                }
                if (flag == 1)
                {
                    item.IsSelected = true;
                }
            }

            return(View(viewModel));
        }