Ejemplo n.º 1
0
        public async Task <List <int> > GetFinishedAccountIdsByCampaignId(int campaignid)
        {
            var campaignAccounts = await _campaignAccountRepository.ListAsync(new CampaignAccountSpecification(campaignid, CampaignAccountStatus.Finished));


            return(campaignAccounts.Select(m => m.AccountId).ToList());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> TakeNoteChangeStatus(int id, CampaignStatus status, string txt_note = "")
        {
            var campaign = await _ICampaignRepository.GetByIdAsync(id);

            DataSelectionStatusAndType();

            try {
                if (campaign != null)
                {
                    campaign.Status       = status;
                    campaign.UserModified = HttpContext.User.Identity.Name;
                    campaign.DateModified = DateTime.Now;
                    campaign.SystemNote   = txt_note;
                    _ICampaignRepository.Update(campaign);


                    NotificationType notificationType = NotificationType.CampaignCanceled;
                    string           msg = string.Empty;
                    if (status == CampaignStatus.Canceled)
                    {
                        notificationType = NotificationType.CampaignCanceled;
                        msg = string.Format("Chiến dịch \"{0}\" bạn tạo đã bị hủy, bởi hệ thống. Lý do: {1}", campaign.Title, txt_note);
                    }
                    else if (status == CampaignStatus.Error)
                    {
                        notificationType = NotificationType.CampaignError;
                        msg = string.Format("Chiến dịch \"{0}\" bạn tạo đã có lỗi, hệ thống đã phát hiện lỗi và gửi thông báo đến bạn. Lý do: {1}", campaign.Title, txt_note);
                    }
                    else if (status == CampaignStatus.Ended)
                    {
                        notificationType = NotificationType.CampaignEnded;
                        msg = string.Format("Chiến dịch \"{0}\" bạn tạo đã kết thúc", campaign.Title);
                    }
                    else if (status == CampaignStatus.Confirmed)
                    {
                        notificationType = NotificationType.CampaignConfirmed;
                        msg = string.Format("Chiến dịch \"{0}\" bạn tạo đã được duyệt bởi hệ thống", campaign.Title);

                        // gửi notification đến các user được chỉ định
                        var campaignAccount = await _ICampaignAccountRepository.ListAsync(new CampaignAccountByAgencySpecification(campaign.Id));

                        foreach (var item in campaignAccount)
                        {
                            if (item.Status == CampaignAccountStatus.AgencyRequest) // Doanh nghiệp mời tham gia chiến dịch
                            {
                                //item.Status = CampaignAccountStatus.AgencyRequest;
                                //await _ICampaignAccountRepository.UpdateAsync(item);

                                try {
                                    var agency = await _IAgencyBusiness.GetAgency(campaign.AgencyId);

                                    NotificationType _notiType      = NotificationType.AgencyRequestJoinCampaign;
                                    string           notify_message = string.Format("Bạn đã được doanh nghiệp \"{0}\" mời tham gia chiến dịch \"{1}\"", agency.Name, campaign.Title);
                                    await _INotificationService.CreateNotification(campaign.Id, EntityType.Account, item.AccountId, _notiType, notify_message, "");
                                }
                                catch { }
                            }
                        }
                        //###########################################################################################################################################
                    }
                    else if (status == CampaignStatus.Completed)
                    {
                        notificationType = NotificationType.CampaignCompleted;
                        msg = string.Format("Chiến dịch \"{0}\" bạn tạo đã hoàn thành", campaign.Title);
                    }

                    if (!string.IsNullOrEmpty(msg))
                    {
                        await _INotificationBusiness.CreateNotificationCampaignByStatus(campaign.Id, campaign.AgencyId, notificationType, msg, txt_note);
                    }
                    TempData["MessageSuccess"] = string.Format("Thay đổi trạng thái \"{0}\" thành công", status.ToString());



                    //if(status == CampaignStatus.Canceled || status == CampaignStatus.Error || status == CampaignStatus.Ended)
                    //{

                    //}
                    //else
                    //{
                    //    TempData["MessageError"] = "Status campaign do not fit";
                    //}
                }
                else
                {
                    TempData["MessageError"] = "Chiến dịch không tồn tại!";
                }
            }
            catch (Exception ex) {
                TempData["MessageError"] = ex.Message;
            }



            return(RedirectToAction("TakeNoteChangeStatus", "Campaign", new { id = id, status = (int)status }));
        }