Exemple #1
0
        static void Main(string[] args)
        {
            //comment when we deploy on master branch becouse we pass parameters in taskScheduler
            //Start Comment

            Console.WriteLine("Enter your argument=");
            string[] tempArr        = new string[1];
            string   commandlinearg = Console.ReadLine();

            if (commandlinearg != "")
            {
                tempArr[0] = commandlinearg;
            }

            //End Comment

            //Replace tempArr with args for master
            foreach (string arg in tempArr)



            {
                if (arg == "SendBalEmail")
                {
                    //get userList whose bal is less than limit and AccountantList
                    AccountantUserList AU = new AccountantUserList();
                    ApiHelper          ap = new ApiHelper();
                    AU = ap.GetAccountantUserList();

                    //calling making email function which in turn calls send email function
                    MakeEmail make = new MakeEmail();
                    make.makeEmail(AU);
                }
            }
        }
        public void makeEmail(AccountantUserList AU)
        {
            List <User>       userList       = new List <User>();
            List <Accountant> accountantList = new List <Accountant> ();

            userList       = AU.userList;
            accountantList = AU.accountantList;

            foreach (var user in userList)
            {
                SendEmail send = new SendEmail();

                string username  = user.firstName;
                string useremail = user.email;
                string userbal   = user.balLeft;


                foreach (var accountant in accountantList)
                {
                    string accountantname = accountant.userInterface;



                    string ApplicationName = ConfigurationManager.AppSettings["SearchExpenseUrl"];
                    string ApplicationUrl  = ConfigurationManager.AppSettings["SearchExpenseUrl"];
                    string LowBalUrl       = ConfigurationManager.AppSettings["SearchExpenseUrl"];

                    string body = "Dear " + accountantname + "," + "<br/><br/>" +
                                  "The advance amount for a user has dropped below minimum threshold level. Please find details below:" + "<br/>" + "<br/>" +
                                  "User: "******"<br/>" +
                                  "Email: " + useremail + "<br/>" +
                                  "Advance Amount: " + userbal + "<br/>" +
                                  "Please take necessary action. You can login to the system here " + ApplicationUrl + "/" + LowBalUrl + "<br/>" + "<br/>" +
                                  "Best," + "<br/>" + "<br/>" +
                                  "Team Prabhat" + "<br/>" +
                                  "Expense Management";

                    string        subject = username + "'s" + " advance is too low" + ApplicationName;
                    List <string> toEmail = new List <string>();

                    toEmail.Add(accountant.loginId);
                    send.subject = subject;
                    send.body    = body;
                    send.toEmail = toEmail;

                    send.sendEmail(send);
                }
            }
        }
        //Get UserList and AccountantList from Apifrom API whom user has bal less than certain limit
        //as set in api config

        public AccountantUserList GetAccountantUserList()
        {
            AccountantUserList AU = new AccountantUserList();

            try
            {
                string appservice    = ConfigurationManager.AppSettings["GetUserBalApi"];
                string appfoldername = ConfigurationManager.AppSettings["ApiFolderName"];


                string result = "";


                HttpResponseMessage response = null; // if   HttpResponseMessage dnt work then add in referece system.net,system.nethttp, system.net.formatiing  etc



                string     struri2 = appfoldername + "/" + "api" + "/" + "AlertEmail" + "/" + "GetUserBalance" + "/";
                HttpClient client  = new HttpClient();
                client.BaseAddress = new Uri(appservice);

                // Add an Accept header for JSON format.
                client.DefaultRequestHeaders.Accept.Add(
                    new MediaTypeWithQualityHeaderValue("application/json"));

                // List data response.
                response = client.GetAsync(struri2).Result;  // Blocking call!

                if (response != null || response.IsSuccessStatusCode)
                {
                    result = response.Content.ReadAsStringAsync().Result;
                }

                AU = JsonConvert.DeserializeObject <AccountantUserList>(result);
            }
            catch (Exception ex)
            {
                string errMsg = ex.Message;
            }
            return(AU);
        }