Пример #1
0
        private NotificationSMS FormatPurchaseSms(NotificationPurchase noti)
        {
            var sms = new NotificationSMS();
            var farmer = _costCentreRepository.GetById(noti.FarmerId);
            if (farmer == null)
                throw new Exception("Invalid farmer");
            sms.HubId = noti.HubId;
            sms.Recipitents = GetPhoneNumber(new List<Guid> { noti.HubId, noti.PurchaseClerkId, noti.FarmerId });
            string body = "";

               body = "PurchaseID= " + noti.DocumentRef + "\n"
               + "Farmer=" + farmer.Name + ",\n"
               + "CUM.Weight=" + noti.CummulativeWeightDetail + ",\n"
               + "and Center=" + noti.CenterName + "\n";

            foreach (var item in noti.Items)
            {
                body +="Commodity=" +  item.ItemName + ",\n" 
                     + "Grade=" + item.Grade + ",\n"
                     + "NT.Weight=" + item.Quantity;
            }
            body += "\nStatus= Purchased";

            sms.SmsBody = body;
            return sms;
        }
Пример #2
0
        private MailMessage FormatPurchase(NotificationPurchase notification)
        {
            var hub = _costCentreRepository.GetById(notification.HubId);
            var clerk = _costCentreRepository.GetById(notification.PurchaseClerkId);
            var farmer = _costCentreRepository.GetById(notification.FarmerId);
            if (farmer == null || hub == null || clerk == null)
                throw new Exception("Invalid Hub , clerk or farmer");
            var msg = new MailMessage();
            GetAddresses(hub.Id).ForEach(msg.To.Add);
            GetAddresses(clerk.Id).ForEach(msg.To.Add);
            GetAddresses(farmer.Id).ForEach(msg.To.Add);
            //msg.To.Add("*****@*****.**");


            if (msg.To.Count == 0) return null;
            msg.Subject = string.Format("Purchase {0} Notification", notification.DocumentRef);
            msg.IsBodyHtml = true;
            string html = "";
            foreach (var item in notification.Items)
            {
                html += string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>", item.ItemName, item.Grade, item.Quantity);
            }
            string body = string.Empty;
            using (StreamReader reader = new StreamReader("service/resources/agrimanagr/PurchaseEmailTemplate.htm"))
            {
                body = reader.ReadToEnd();
            }
            body = body.Replace("{Hub}", hub.Name + " (" + hub.CostCentreCode + ")");
            body = body.Replace("{Clerk}", notification.ServedBy);
            body = body.Replace("{Farmer}", farmer.Name+" ("+farmer.CostCentreCode+")");
            body = body.Replace("{DocumentRef}", notification.DocumentRef);
            body = body.Replace("{Items}", html);
            body = body.Replace("{CummulativeWeightDetail}", notification.CummulativeWeightDetail);
            body = body.Replace("{CenterName}", notification.CenterName);

            msg.Body = body;
            return msg;
        }