예제 #1
0
        public async Task <IActionResult> Index(SentReport report, int reportId)
        {
            var user = await _signInManager.UserManager.GetUserAsync(User);

            var        _customer   = _dbContext.Customers.First(x => x.ApplicationUserId == user.Id);
            SentReport SmsOverview = new SentReport();

            if (report == null)
            {
                SmsOverview = await _dbContext.SendReports.Include(c => c.SentSmsDetails).Where(x => x.CustomerId == _customer.ID).FirstAsync(x => x.ID == report.ID);
            }
            else
            {
                SmsOverview = await _dbContext.SendReports.Include(c => c.SentSmsDetails).Where(x => x.CustomerId == _customer.ID).FirstAsync(x => x.ID == reportId);
            }
            return(View(SmsOverview));
        }
예제 #2
0
        public async Task <IActionResult> SendSms(MessageObjectViewModel messageObjectViewModel, int[] groups, int[] contacts)
        {
            var user = await _signInManager.UserManager.GetUserAsync(User);

            var _customer = _dbContext.Customers.First(x => x.ApplicationUserId == user.Id);

            if (groups != null)
            {
                foreach (var group in groups)
                {
                    var assig = await _dbContext.GroupAssigns.Where(x => x.Group.ID == group).ToListAsync();

                    foreach (var item in assig)
                    {
                        var _contact = await _dbContext.Contacts.FirstAsync(x => x.ID == item.ContactID);

                        messageObjectViewModel.GroupedContacts.Add(_contact);
                    }
                }
            }
            if (contacts != null)
            {
                foreach (var contact in contacts)
                {
                    var _contact = await _dbContext.Contacts.FindAsync(contact);

                    messageObjectViewModel.Contacts.Add(_contact);
                }
            }
            SMSServiceEBulk eBulk    = new SMSServiceEBulk();
            var             Response = await eBulk.SendSMSPOSTMethodAsync(messageObjectViewModel);

            if (Response.ValidationStatus == "Failed")
            {
                ///Throw Client Side Validation for No recepient
                return(RedirectToAction(nameof(SendSms)));
            }
            SentReport Report = new SentReport()
            {
                CustomerId = _customer.ID,
                Status     = Response.Status ? "Success" : "Failed",
                UnitsUsed  = Response.UnitsUsed,
                Message    = Response.Message,
                Subject    = Response.Subject,
                DateSent   = DateTime.Now.Date,
            };
            var SmsDetails = new List <SentSmsDetails>();

            foreach (var item in Response.ReturnObjects)
            {
                SmsDetails.Add(new SentSmsDetails()
                {
                    Name = item.Name, Recipient = item.Recipient, IsDeliveryReportChecked = Response.Status, Date = DateTime.Now.Date, SentReport = Report, SentReportID = Report.ID
                });
            }
            Report.SentSmsDetails = SmsDetails;
            if (Report.Status == "Failed")
            {
                //Throw ClientSide Exception for failed message
            }
            else
            {
                _dbContext.Add(Report);
                _dbContext.SaveChanges();
            }
            return(RedirectToAction(nameof(Index), Report));
        }