Exemplo n.º 1
0
        public string BuildStatusChangeMessageBody(string templateName, RepairDetailsResponse repair, CustomerDecisionLink links)
        {
            var email       = repair.CustomerDetails.Email;
            var builder     = new BodyBuilder();
            var _pathToFile = GetTemplateFilePathAsync(templateName);

            using (StreamReader SourceReader = System.IO.File.OpenText(_pathToFile))
            {
                builder.HtmlBody = SourceReader.ReadToEnd();
            }

            //{0} : Customer.Name
            //{1} : RepairStatus.name

            string messageBody = string.Format(builder.HtmlBody,
                                               repair.CustomerDetails.Name,
                                               repair.StatusName
                                               );

            return(messageBody);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> UpdateRepair(int?repairId, int?saparepartId, int?quantity)
        {
            RepairDetailsResponse repair = new RepairDetailsResponse();

            if (repairId != null)
            {
                repair = await _repairService.GetRepairByIdAsync(repairId.Value);

                var key  = "currentRepairId";
                var data = repairId.Value;
                HttpContext.Session.SetString(key, JsonConvert.SerializeObject(data));
            }

            RepairUpdateRequest model = new RepairUpdateRequest();

            var result = HttpContext.Session.GetString("repairUpdateRequest");

            if (result != null)
            {
                var data            = JsonConvert.DeserializeObject <RepairUpdateRequest>(result);
                var currentRepairId = HttpContext.Session.GetString("currentRepairId");

                if (data.RepairId != int.Parse(currentRepairId))
                {
                    HttpContext.Session.Clear();
                }
            }

            var str = HttpContext.Session.GetString("repairUpdateRequest");

            if (str != null)
            {
                var data = JsonConvert.DeserializeObject <RepairUpdateRequest>(str);
                model = data;
            }
            else
            {
                model.Links = new Core.Models.Healpers.CustomerDecisionLink();
                var host   = HttpContext.Request.Host.Host;
                var port   = HttpContext.Request.Host.Port;
                var apiUri = host + ":" + port;
                if (port == null)
                {
                    apiUri = host;
                }
                model.Links.DecisionLink = Url.Action("CustomerDecision", "Repair", new { repairId = repair.RepairId }, "https", apiUri);

                model.CustomerId  = repair.CustomerId;
                model.Description = repair.Description;
                model.RepairId    = repair.RepairId;
                model.StatusId    = repair.StatusId;
                model.ProductId   = repair.ProductId;

                if (repair.RepairItems.Any() && repair.StatusId != 1)
                {
                    model.RepairItems = new List <RepairItemAddRequest>();

                    foreach (var item in repair.RepairItems)
                    {
                        RepairItemAddRequest req = new RepairItemAddRequest()
                        {
                            Quantity     = item.Quantity,
                            RepairId     = repair.RepairId,
                            SaparePartId = item.SaparePart.SaparePartId
                        };

                        model.RepairItems.Add(req);
                    }
                }
                else
                {
                    model.RepairItems = new List <RepairItemAddRequest>();
                }

                var key  = "repairUpdateRequest";
                var data = model;
                HttpContext.Session.SetString(key, JsonConvert.SerializeObject(data));

                var keyCurrentRepairId  = "currentRepairId";
                var dataCurrentRepairId = model.RepairId;
                HttpContext.Session.SetString(keyCurrentRepairId, JsonConvert.SerializeObject(dataCurrentRepairId));
            }

            if (saparepartId != null && quantity != null)
            {
                var repairCurrentData = await _repairService.GetRepairByIdAsync(int.Parse(HttpContext.Session.GetString("currentRepairId")));

                var newRepairItem = new RepairItemAddRequest()
                {
                    RepairId        = model.RepairId,
                    SaparePartId    = saparepartId.Value,
                    Quantity        = quantity.Value,
                    Name            = repairCurrentData.SapareParts.Where(x => x.SaparePartId == saparepartId).Select(y => y.Name).First(),
                    ReferenceNumber = repairCurrentData.SapareParts.Where(x => x.SaparePartId == saparepartId).Select(y => y.ReferenceNumber).First(),
                    Price           = repairCurrentData.SapareParts.Where(x => x.SaparePartId == saparepartId).Select(y => y.Price).First()
                };

                if (model.RepairItems != null)
                {
                    model.RepairItems.Add(newRepairItem);

                    var key  = "repairUpdateRequest";
                    var data = model;
                    HttpContext.Session.SetString(key, JsonConvert.SerializeObject(data));
                }

                return(RedirectToAction("UpdateRepair", "Repair", new { repairId = model.RepairId }));
            }

            return(View(model));
        }
Exemplo n.º 3
0
        public async Task SendRepairAddNotifyEmailAsync(string templateName, string subject, RepairDetailsResponse repair)
        {
            var email       = repair.CustomerDetails.Email;
            var builder     = new BodyBuilder();
            var _pathToFile = GetTemplateFilePathAsync(templateName);

            using (StreamReader SourceReader = System.IO.File.OpenText(_pathToFile))
            {
                builder.HtmlBody = SourceReader.ReadToEnd();
            }

            //{0} : Customer.Name
            //{1} : RepairStatus.name

            string messageBody = string.Format(builder.HtmlBody,
                                               repair.CustomerDetails.Name,
                                               repair.StatusName
                                               );

            await SendEmailAsync(email, subject, messageBody);
        }
Exemplo n.º 4
0
        public async Task SendRepairStatusChangeEmailAsync(string templateName, string subject, RepairDetailsResponse repair, CustomerDecisionLink links)
        {
            var email = repair.CustomerDetails.Email;

            // Use diferent messageBody Builder if links are empty.
            if (links != null)
            {
                string messageBody = BuildCustomerDecisionMessageBody(templateName, repair, links);
                await SendEmailAsync(email, subject, messageBody);
            }
            else
            {
                string messageBody = BuildStatusChangeMessageBody(templateName, repair, links);
                await SendEmailAsync(email, subject, messageBody);
            }
        }