Exemplo n.º 1
0
        public object ToJson(string EntityMode)
        {
            EntityMode = EntityMode.StringAndTrim().ToLower();
            if (EntityMode == "managerfee" || EntityMode == "details")
            {
                return(new
                {
                    this.Address,
                    this.Archived,
                    this.ArchiveDate,
                    this.ChangeDate,
                    this.ChangerID,
                    this.Comments,
                    this.ContractorID,
                    this.Cost,
                    this.WorksCost,
                    this.CreateDate,
                    this.CreatorID,
                    this.Deleted,
                    this.ID,
                    this.Name,
                    this.IncomeSum,
                    this.OutgoingSum,
                    this.ContractID,
                    this.DateEnd,
                    this.DaysEnd,
                    this.DaysFromTypeID,
                    this.DaysTypeID,
                    this.MissingAct,
                    this.MissingContract,
                    this.DateSign,
                    this.ResponsibleID,
                    this.ManagerFee,
                    this.ExpensesSum,
                    this.ParentID,
                    this.SubcontractorID,
                    this.ManagerFeeAmount,
                    this.ManagerFeePaid,
                    this.StatusID,
                    this.EmployeeID,
                    this.TypeID,
                    this.Number,
                    this.Contacts,
                    this.FullName,
                    this.Code,
                    InvoicesDebt = this.InvoicesDebt,
                    ParentName = this.ParentProject != null ? this.ParentProject.Name : "отсутствует",
                    ResponsibleName = UserResponsible != null ? UserResponsible.FullName : "",
                    AdvanceDate = AdvancePayment == null ? "" : AdvancePayment.Date.ToShortDateString(),
                    AdvanceSum = AdvancePayment == null ? "" : AdvancePayment.Sum.ToDecimalString(),
                    TypeName = this.ProjectType != null ? this.ProjectType.Name : string.Empty,
                    EmployeeName = this.Employee != null ? this.Employee.FullName : string.Empty
                });
            }
            else if (EntityMode == "gainreport" || EntityMode == "invoicesreport" || EntityMode == "tasksreport")
            {
                Dictionary <string, object> result = new Dictionary <string, object>();
                result["ID"]         = ID;
                result["Number"]     = Number;
                result["Name"]       = Name;
                result["FullName"]   = FullName;
                result["DateEnd"]    = DateEnd;
                result["CreateDate"] = CreateDate;
                result["DateSign"]   = DateSign;
                result["Contacts"]   = Contacts;
                result["Address"]    = Address;
                result["Status"]     = this.Status != null?this.Status.ToJson() : null;

                result["StatusName"]         = this.Status != null ? this.Status.Name : string.Empty;
                result["StatusID"]           = this.StatusID;
                result["Code"]               = this.Code;
                result["EmployeeName"]       = this.Employee != null ? this.Employee.FullName : string.Empty;
                result["ResponsibleName"]    = UserResponsible != null ? UserResponsible.FullName : "";
                result["ContractorName"]     = Contractor != null ? Contractor.FullName : "";
                result["ContractorContacts"] = Contractor != null?Contractor.ContactsToString() : "";

                return(result);
            }
            return(ToJson());
        }
Exemplo n.º 2
0
        public void SendNotification(BuildingEntities db)
        {
            string tcreator     = ProjectTask != null ? ProjectTask.Creator : string.Empty;
            string TemplateName = "ProjectTaskMessage_Inserted";

            string[] notifies = this.Notify.StringAndTrim().Split(';');

            List <string> emails = new List <string>();

            this.Notify = "";
            foreach (string n in notifies)
            {
                this.Notify += n + ":";
                switch (n)
                {
                case "contractor":
                    if (Contractor != null)
                    {
                        string email = Contractor.Email.StringAndTrim();
                        if (email.IsNotNullOrEmpty())
                        {
                            emails.Add(email);
                            this.Notify += email + ";";
                        }
                        email = Contractor.GetEmail(db).StringAndTrim();
                        emails.AddRange(email.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries));
                        this.Notify += email;
                        this.Notify  = this.Notify.Trim(';');
                    }
                    break;

                case "employee":
                    if (Employee != null)
                    {
                        string email = Employee.GetEmails();
                        emails.Add(email);
                        this.Notify += email;
                    }
                    break;

                case "creator":
                    if (tcreator.IsNotNullOrEmpty())
                    {
                        User user = db.Users.FirstOrDefault(val => !val.Deleted && val.Login == tcreator);
                        if (user != null && user.Email.IsNotNullOrEmpty())
                        {
                            emails.Add(user.Email);
                            this.Notify += user.Email;
                        }
                    }
                    break;

                case "responsible":
                    if (Responsible != null)
                    {
                        emails.Add(Responsible.Email);
                        this.Notify += Responsible.Email;
                    }
                    break;

                case "last":
                    if (ProjectTask != null)
                    {
                        ProjectTaskMessage m = ProjectTask.Messages.OrderBy(val => val.ID).LastOrDefault();
                        if (m != null && m.ID > 0)
                        {
                            User user = db.Users.FirstOrDefault(val => !val.Deleted && val.Login == m.Creator);
                            if (user != null && user.Email.IsNotNullOrEmpty())
                            {
                                emails.Add(user.Email);
                                this.Notify += user.Email;
                            }
                        }
                    }
                    break;

                default:
                    if (n.StartsWith("another:"))
                    {
                        int  userID = n.Split(':').Last().ToIntOrDefault() ?? 0;
                        User user   = db.Users.FirstOrDefault(val => !val.Deleted && val.ID == userID);
                        if (user != null && user.Email.IsNotNullOrEmpty())
                        {
                            emails.Add(user.Email);
                            this.Notify += user.Email;
                        }
                    }
                    break;
                }
                this.Notify += ";";
            }
            this.Notify = this.Notify.Trim(';');

            emails = emails.Where(val => val.IsNotNullOrEmpty()).ToList();

            EmailTemplate template = Settings.GetEmailTemplate(TemplateName);

            if (template.Body.IsNullOrEmpty() || !emails.Any())
            {
                return;
            }

            DynamicDocuments.DataProvider dp = new Models.DynamicDocuments.DataProvider()
            {
                Project = this.ProjectTask.Project,
                Number  = this.ID.ToString(),
                //User = this.UserResponsible,
                Data = new
                {
                    //User = this.UserResponsible,
                    Task    = this.ProjectTask,
                    Message = this
                              //Employee = this.Employee,
                              //Status = this.Status
                }
            };

            try
            {
                string mailSubject = DynamicDocumentGenerator.Generator.GenerateText(template.Subject, dp);
                string mailBody    = DynamicDocumentGenerator.Generator.GenerateText(template.Body, dp);

                EmailHelper emailHelper = new EmailHelper();
                emailHelper.SendEmail(mailSubject, mailBody, string.Join(";", emails.Distinct()));
            }
            catch (Exception ex)
            {
                new Log().Error(ex);
            }
        }