示例#1
0
        public ActionResult Decline(DeclineRequestViewModel model)
        {
            var request = this.requestToProviderService.GetById(model.RequestId);

            //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 event that request is not approved
            var aEvent = new KAssets.Models.Event
            {
                UserId             = request.FromId,
                Content            = "Your request to provider was not approved. " + model.Message,
                Date               = DateTime.Now,
                EventRelocationUrl = "/Orders/ProviderOrder/ViewHistoryRequest/" + model.RequestId
            };

            this.eventService.Add(aEvent);
            this.requestToProviderService.SetFinished(model.RequestId);

            return(Redirect("/Orders/ProviderOrder/GetRequestsForApproving"));
        }
示例#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"));
        }
示例#3
0
        public ActionResult AddProviderOffer(AddProviderToRequestViewModel req)
        {
            var userOrg = this.userService.GetById(this.User.Identity.GetUserId()).Site.OrganisationId;

            if (userOrg != this.requestToProviderService.GetById(req.PoId).From.Site.OrganisationId)
            {
                return(Redirect("/Home/NotAuthorized"));
            }

            if (!ModelState.IsValid)
            {
                var errorList = ModelState.ToDictionary(
                    kvp => kvp.Key,
                    kvp => kvp.Value.Errors.Select(e => e.ErrorMessage).ToArray()
                    );

                //Put the errors and model values to tempdata
                TempData["Keys"]   = JsonConvert.SerializeObject(errorList);
                TempData["Values"] = JsonConvert.SerializeObject(req.Offers);

                var url = this.HttpContext.Request.UrlReferrer.ToString();
                TempData["Show"] = 1;
                return(Redirect(url));
            }

            //Check is there a request with this id
            if (!this.requestToProviderService.GetAll().Any(x => x.Id == req.PoId))
            {
                this.ModelState.AddModelError("PoId", ProviderOrderTr.EixstReq);
                var errorList = ModelState.ToDictionary(
                    kvp => kvp.Key,
                    kvp => kvp.Value.Errors.Select(e => e.ErrorMessage).ToArray()
                    );

                //Put the errors and model values to tempdata
                TempData["Keys"]   = JsonConvert.SerializeObject(errorList);
                TempData["Values"] = JsonConvert.SerializeObject(req.Offers);

                var url = this.HttpContext.Request.UrlReferrer.ToString();
                TempData["Show"] = 1;
                return(Redirect(url));
            }
            //Check are there a offers for this request
            var po = this.requestToProviderService.GetById(req.PoId);

            if (po.WantItems != null && po.SendOffers.Count != 0)
            {
                this.ModelState.AddModelError("PoId", ProviderOrderTr.AddedOffers);
                var errorList = ModelState.ToDictionary(
                    kvp => kvp.Key,
                    kvp => kvp.Value.Errors.Select(e => e.ErrorMessage).ToArray()
                    );

                //Put the errors and model values to tempdata
                TempData["Keys"]   = JsonConvert.SerializeObject(errorList);
                TempData["Values"] = JsonConvert.SerializeObject(req.Offers);

                var url = this.HttpContext.Request.UrlReferrer.ToString();
                TempData["Show"] = 1;
                return(Redirect(url));
            }


            //Add offers to the request
            foreach (var item in req.Offers)
            {
                this.requestToProviderService.AddOffer(new ProviderItemOffer
                {
                    Brand = item.Brand,
                    Model = item.ItemModel,
                    Price = new Price {
                        Value = item.Price, CurrencyId = item.SelectedCurrency
                    },
                    Quantity = item.Quantity,
                    Producer = item.Producer
                }, po.Id);
            }

            //Add a event that are added offers to request
            var aEvent = new KAssets.Models.Event
            {
                Content            = "There are new request to provider for approving! ",
                Date               = DateTime.Now,
                EventRelocationUrl = "/Orders/ProviderOrder/GetRequestsForApproving"
            };

            this.eventService.AddForUserGroup(aEvent, "Approve request to provider",
                                              this.userService.GetUserOrganisationId(this.User.Identity.GetUserId()));

            return(Redirect("/Home/Index"));
        }