private bool UploadFileToBuilding(tblBuilding building, Data.ManagementPackData.ManagementPack dataItem, out string url)
        {
            string fileName    = "ManagementPack_" + dataItem.Period.ToString("yyyy_MMM") + ".pdf";
            string description = "Management Pack " + dataItem.Period;

            url = _ClientPortal.UploadBuildingDocument(DocumentCategoryType.MonthlyFinancial,
                                                       dataItem.Period,
                                                       building.id, description, fileName, dataItem.ReportData, string.Empty);
            return(true);
        }
Example #2
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     using (OpenFileDialog ofd = new OpenFileDialog())
     {
         if (ofd.ShowDialog() == DialogResult.OK && !String.IsNullOrEmpty(ofd.FileName))
         {
             var fileData = File.ReadAllBytes(ofd.FileName);
             _ClientPortal.UploadBuildingDocument(DocumentCategoryType.Letter, DateTime.Today, building.ID, Path.GetFileName(ofd.FileName), Path.GetFileName(ofd.FileName), fileData, string.Empty);
             ListFiles();
         }
     }
 }
Example #3
0
        private void btnSelectFile_Click(object sender, EventArgs e)
        {
            if (cbDocumentCategory.SelectedValue == null)
            {
                Controller.HandleError("Please select a document cateogory.", "Validation Error");
                return;
            }

            if (_SelectedBuilding == null)
            {
                Controller.HandleError("Please select a building.", "Validation Error");
                return;
            }

            if (string.IsNullOrWhiteSpace(tbTitle.Text))
            {
                Controller.HandleError("File title required", "Validation Error");
                return;
            }

            var documentType = (DocumentCategoryType)cbDocumentCategory.SelectedValue;

            if (fdOpen.ShowDialog() == DialogResult.OK)
            {
                var filePath = fdOpen.FileName;
                if (!IsValidPdf(filePath))
                {
                    Controller.HandleError("Not a valid PDF file");
                    return;
                }

                clientPortal.UploadBuildingDocument(documentType, DateTime.Now, _SelectedBuilding.ID, tbTitle.Text, filePath, string.Empty);

                Controller.ShowMessage("File Uploaded");

                LoadSelectedBuilding(_SelectedBuilding);
            }
        }
        private void SendCalenderInvite(CalendarPrintItem entry)
        {
            if (string.IsNullOrWhiteSpace(entry.PMEmail))
            {
                Controller.HandleError("Email address not found for " + entry.PM);
                return;
            }

            var calendarInvite = CreateCalendarInvite(entry.BuildingName + " - " + entry.Event, "", entry.Venue, entry.EventDate, entry.EventToDate != null ? entry.EventToDate.Value : entry.EventDate.AddHours(2));
            Dictionary <string, byte[]> attachments = new Dictionary <string, byte[]>();

            attachments.Add("Appointment.ics", calendarInvite);
            string subject = entry.InviteSubject;

            if (String.IsNullOrWhiteSpace(subject))
            {
                subject = entry.BuildingName + " - " + entry.Event;
            }

            string bodyContent = entry.InviteBody;

            if (String.IsNullOrWhiteSpace(bodyContent))
            {
                bodyContent = "";
            }

            string bccEmail = entry.BCCEmailAddress;

            if (bccEmail == string.Empty)
            {
                bccEmail = null;
            }

            //add aditional attachments
            using (var context = SqlDataHandler.GetDataContext())
            {
                var attach = context.CalendarEntryAttachmentSet.Where(a => a.BuildingCalendarEntryId == entry.Id).ToList();
                foreach (var a in attach)
                {
                    attachments.Add(a.FileName, a.FileData);
                }

                List <string> toAddress = new List <string>();
                toAddress.Add(entry.PMEmail);
                if (entry.EventyType == CalendarEntryType.Staff)
                {
                    var qInvite = from i in context.CalendarUserInviteSet
                                  where i.CalendarEntryId == entry.Id
                                  select i.User.email;

                    toAddress.AddRange(qInvite.ToList());
                }

                if (!Email.EmailProvider.SendCalendarInvite(entry.PMEmail, toAddress.Distinct().ToArray(), subject, bodyContent, attachments, bccEmail))
                {
                    Controller.HandleError("Error seding email ", "Email error");
                }

                if (entry.NotifyTrustees && entry.EventyType == CalendarEntryType.Financial)
                {
                    var customers    = Controller.pastel.AddCustomers(entry.BuildingAbreviation, entry.BuildingDataPath, true);
                    var dbCustomers  = context.CustomerSet.Where(a => a.BuildingId == entry.BuildingId && a.IsTrustee == true).ToList();
                    var clientPortal = new AstrodonClientPortal(SqlDataHandler.GetClientPortalConnectionString());

                    if (dbCustomers.Count() > 0 && Controller.AskQuestion("Are you sure you want to send the invite to " + dbCustomers.Count().ToString() + " trustees?"))
                    {
                        //upload building documents

                        Dictionary <string, string> trusteeAttachmentLinks = new Dictionary <string, string>();
                        foreach (var fileName in attachments.Keys.ToList())
                        {
                            if (fileName != "Appointment.ics")
                            {
                                var url = clientPortal.UploadBuildingDocument(DocumentCategoryType.PrivilegedCorrespondence, DateTime.Today, entry.BuildingId.Value, Path.GetFileNameWithoutExtension(fileName), fileName, attachments[fileName], "From Email");
                                trusteeAttachmentLinks.Add(fileName, url);
                            }
                        }

                        foreach (var dbCustomer in dbCustomers)
                        {
                            var trustee = customers.Where(a => a.accNumber == dbCustomer.AccountNumber).FirstOrDefault();
                            if (trustee != null)
                            {
                                if (trustee.Email != null && trustee.Email.Length > 0)
                                {
                                    if (!Email.EmailProvider.SendTrusteeCalendarInvite(entry.PMEmail, trustee.Email, subject, bodyContent, attachments, bccEmail, trusteeAttachmentLinks))
                                    {
                                        Controller.HandleError("Error seding email", "Email error");
                                    }
                                }
                            }
                        }

                        var itm = context.BuildingCalendarEntrySet.Single(a => a.id == entry.Id);
                        itm.TrusteesNotified   = true;
                        entry.TrusteesNotified = true;
                        context.SaveChanges();
                        BindDataGrid();
                    }
                }
            }
        }