Esempio n. 1
0
        private List <ReportCustomerViewModel> ListCustomerEvent(PlanFilter filter)
        {
            var list =
                eventService.GetAll(
                    x =>
                    (filter.Month == 0 || x.DateBegin.Month == filter.Month) && x.DateBegin.Year == filter.Year &&
                    x.CreatedById == filter.Id && x.IsEventAction == false).Select(x => new ReportCustomerViewModel
            {
                DateTime    = x.DateBegin,
                CompanyName = x.CRMCustomer.CompanyShortName,
                ContactName = x.CRMCustomer.CRMContacts.Aggregate("\n", (current, u) => current + (u.FullName + "/" + u.Phone + "<br/>"))
            });

            return(list.ToList());
        }
Esempio n. 2
0
        public JsonResult ListByCus(long refId, bool isEventAction = false)
        {
            var sort = new SSM.Services.SortField("Subject", true);

            ViewBag.IsEventAction = isEventAction;
            var totalRow = 0;
            var page     = new Pager()
            {
                CurrentPage = 1, PageSize = 100
            };
            IEnumerable <CRMEventModel> listEvents = eventService.GetAll(sort, out totalRow, page, refId, isEventAction, CurrenUser);

            crmCustomer = crmCustomer ?? crmCustomerService.GetModelById(refId);
            var value = new
            {
                Views      = this.RenderPartialView("_ListForCus", listEvents),
                CloseOther = true,
                Title      = string.Format(@"Danh sách {0} của khách hàng {1}", isEventAction ? "sự kiện" : "viếng thăm", crmCustomer.CompanyShortName),
            };

            return(JsonResult(value, true));
        }
Esempio n. 3
0
        public void Execute(IJobExecutionContext context)
        {
            var currendate = DateTime.Now.Date;
            var startDate  = new DateTime(currendate.Year, currendate.Month, currendate.Day, 6, 0, 0);
            var endDate    = new DateTime(currendate.Year, currendate.Month, currendate.Day, 23, 59, 59);

            if (DateTime.Now < startDate && DateTime.Now > endDate)
            {
                return;
            }
            var list = eventService.GetAll(x => x.Status == (byte)CRMEventStatus.Follow && x.IsSchedule && (x.DateBegin >= currendate ||
                                                                                                            (x.DateEnd >= currendate && x.DateEnd <= currendate.AddDays(1))) &&
                                           (x.LastTimeReminder == null || x.LastTimeReminder.Value.Date != currendate));

            foreach (var schedule in list)
            {
                try
                {
                    var nowtime = DateTime.Now;
                    if (schedule == null)
                    {
                        continue;
                    }
                    var lastDate = schedule.LastTimeReminder;
                    if (lastDate != null && lastDate.Value.Date == currendate)
                    {
                        continue;
                    }
                    var      jobDate = currendate.ToString("M/d/yyyy") + " " + schedule.TimeOfRemider;
                    DateTime dt;
                    if (!DateTime.TryParse(jobDate, out dt))
                    {
                        continue;
                    }
                    bool isSendMail = true;
                    if (currendate <= schedule.DateEnd && !string.IsNullOrEmpty(schedule.DayWeekOfRemider))
                    {
                        var dayOfWs = schedule.DayWeekOfRemider.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => int.Parse(x));
                        if (!dayOfWs.Contains((int)nowtime.DayOfWeek))
                        {
                            isSendMail = false;
                        }
                        if (schedule.DateBegin == schedule.DateEnd)
                        {
                            isSendMail = true;
                        }
                    }

                    if (!isSendMail || nowtime < dt.AddMinutes(-1))
                    {
                        continue;
                    }
                    Logger.LogDebug("Process send email for Event");
                    var    admin          = usersServices.FindEntity(x => x.UserName.ToLower() == "admin");
                    var    user           = !string.IsNullOrEmpty(schedule.User.Email) ? schedule.User : admin;
                    var    emailTo        = string.IsNullOrEmpty(schedule.User.Email) ? admin.Email : schedule.User.Email;
                    string emailJoinEvent = string.Empty;
                    if (schedule.CRMFollowEventUsers != null && schedule.CRMFollowEventUsers.Any())
                    {
                        emailJoinEvent = schedule.CRMFollowEventUsers.Where(x => !string.IsNullOrEmpty(x.User.Email)).Aggregate(emailJoinEvent,
                                                                                                                                (current, u) => current + (u.User.Email + ","));
                    }
                    emailTo = emailTo + "," + emailJoinEvent;
                    string actionUrl = $"{Helpers.Site}/CRMEvent/Detail/{schedule.Id}";
                    var    link      = $"Bạn có thể <a href=\"{actionUrl}\" >click vào đây</a> để xem chi tiết";
                    var    model     = new EmailModel()
                    {
                        EmailTo = emailTo,
                        EmailCc = admin.Email,
                        User    = user,
                        Subject = $"[{schedule.User.FullName}], You have 1 {(schedule.IsEventAction ? "event" : "visit")} {schedule.CRMCustomer.CompanyName}",
                        Message =
                            $"Dear [{schedule.User.FullName}] <br/> You have 1 {(schedule.IsEventAction ? "event" : "visit")}  at {jobDate} <br/> {schedule.Description}  .<br/> {link}",
                        IsUserSend = false,
                        IdRef      = schedule.Id,
                    };
                    var errorMessages = string.Empty;
                    var email         = new EmailCommon {
                        EmailModel = model
                    };
                    if (!email.SendEmail(out errorMessages, true))
                    {
                        Logger.LogError(errorMessages);
                    }
                    else
                    {
                        schedule.LastTimeReminder = DateTime.Now;
                        eventService.Commited();
                        Logger.Log("Send mail schechdule at " + nowtime.ToString("g"));
                    }
                }
                catch (Exception e)
                {
                    Logger.LogError("Loi job event send mail schedule:");
                    Logger.LogError(e);
                }
            }
        }