protected override async Task OnParametersSetAsync()
        {
            _editContext = new EditContext(_tripFormModel);

            var result = int.TryParse(RunsheetId, out _id);

            _runsheet = await Unit.Runsheets.GetByIdAsync(_id);

            _activeTrip = await Unit.Trips.GetTripWithChildrenByRunsheetId(_id);

            if (_activeTrip != null)
            {
                _tripFormModel = TripMapper.MapTrip(_activeTrip, _tripFormModel);
            }

            if (_activeTrip == null)
            {
                _activeTrip = new Trip()
                {
                    InProgress = true
                };
                _tripFormModel.StartTime  = LocalTimeUtility.GetLocalTime();
                _tripFormModel.InProgress = true;
            }
        }
        private async Task UpdateModel()
        {
            _activeTrip = TripMapper.MapTrip(_tripFormModel, _activeTrip);
            _runsheet   = await Unit.Runsheets.GetByIdAsync(_id);

            if (_activeTrip.Id == 0)
            {
                _runsheet.Trips.Add(_activeTrip);
                await Unit.Runsheets.UpdateAsync(_runsheet);
            }
            else
            {
                await Unit.Trips.UpdateAsync(_activeTrip);
            }
        }
Exemple #3
0
        private async Task GetRunsheet()
        {
            var user = await UserInfoProvider.GetUser();

            var userId = await UserInfoProvider.GetId();

            if (user.IsInRole("Manager") || user.IsInRole("Admin"))
            {
                var result = await Unit.Runsheets.GetAllWithChildren();

                _runsheet = result.FirstOrDefault(x => x.Date.Date == _date.Date && x.UserId == _userSelectBoxValue);
            }
            else
            {
                var result = await Unit.Runsheets.GetAllWithChildren();

                _runsheet = result.FirstOrDefault(x => x.UserId == userId && x.Date.Date == _date.Date);
            }
        }
        //public static async Task SendEmail()
        //{
        //    var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
        //    var client = new SendGridClient(apiKey);
        //    var from = new EmailAddress("*****@*****.**", "Alex");
        //    var subject = "Sending with SendGrid is Fun";
        //    var to = new EmailAddress("*****@*****.**", "Myself");
        //    var plainTextContent = "and easy to do anywhere, even with C#";
        //    var htmlContent = "<strong>and easy to do anywhere, even with C#</strong>";
        //    var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
        //    var response = await client.SendEmailAsync(msg);
        //}

        public static async Task SendEmail(Runsheet runsheet, string email)
        {
            var from = new EmailAddress("*****@*****.**", "Alex");
            var to   = new EmailAddress(email, "Myself");

            var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
            var client = new SendGridClient(apiKey);

            var subject = $"Runsheet For {runsheet.Driver} {runsheet.Date.ToShortDateString()}";

            var msg = MailHelper.CreateSingleEmail(from, to, subject, " ", "<strong></strong>");

            var bytes = File.ReadAllBytes("wwwroot/CsvFiles/OutputPdf.pdf");
            var file  = Convert.ToBase64String(bytes);

            msg.AddAttachment($"Runsheet{runsheet.Driver}.pdf", file);

            var response = await client.SendEmailAsync(msg);
        }