Пример #1
0
        protected override async Task DoUpdate(ContactModel model, int id, Contact entity)
        {
            entity.E164Mobile = MobileUtil.GetE164PhoneNumber(model.Mobile);
            entity.Region     = MobileUtil.GetRegionName(model.Mobile);

            await context.UpdateAsync(entity);
        }
Пример #2
0
        protected override async Task <Contact> DoCreate(ContactModel model, Contact entity)
        {
            entity = new Contact();

            entity.Name          = model.Name;
            entity.Mobile        = model.Mobile;
            entity.E164Mobile    = MobileUtil.GetE164PhoneNumber(model.Mobile);
            entity.Region        = MobileUtil.GetRegionName(model.Mobile);
            entity.HomePhoneArea = model.HomePhoneArea;

            entity.HomePhone        = model.HomePhone;
            entity.CompanyPhoneArea = model.CompanyPhoneArea;
            entity.CompanyPhone     = model.CompanyPhone;
            entity.CompanyPhoneExt  = model.CompanyPhoneExt;
            entity.Email            = model.Email;

            entity.Msn          = model.Msn;
            entity.Description  = model.Description;
            entity.Birthday     = model.Birthday;
            entity.ImportantDay = model.ImportantDay;
            entity.Gender       = model.Gender;

            entity.Groups        = null;
            entity.CreatedUserId = CurrentUserId;

            entity = await context.InsertAsync(entity);

            return(entity);
        }
        private ActionResult HandleUploadedFile(List <UploadedMessageReceiverList> list, UploadedFile uploadedFile, bool useParam)
        {
            using (var scope = this.unitOfWork.CreateTransactionScope())
            {
                var entities = list.Select((model, i) => new UploadedMessageReceiver
                {
                    RowNo      = i + 1,
                    Name       = model.Name,
                    Mobile     = model.Mobile,
                    E164Mobile = MobileUtil.GetE164PhoneNumber(model.Mobile),
                    Region     = MobileUtil.GetRegionName(model.Mobile),
                    Email      = model.Email,

                    SendTime             = Converter.ToUniversalTime(model.SendTime, Converter.yyyyMMddHHmm, ClientTimezoneOffset),
                    ClientTimezoneOffset = ClientTimezoneOffset,
                    SendTimeString       = model.SendTime,
                    UseParam             = useParam,
                    Param1            = model.Param1,
                    Param2            = model.Param2,
                    Param3            = model.Param3,
                    Param4            = model.Param4,
                    Param5            = model.Param5,
                    CreatedUserId     = CurrentUserId,
                    CreatedTime       = uploadedFile.CreatedTime,
                    UploadedFile      = uploadedFile,
                    UploadedSessionId = uploadedFile.Id,
                }).ToList(); // 要加上 ToList,否則會檢驗呈無效名單,目前不知道為什麼

                var error      = string.Empty;
                var blacklists = context.Set <Blacklist>().Where(p => p.CreatedUserId == CurrentUserId).ToList();
                foreach (var entity in entities)
                {
                    this.validationService.Validate(entity, blacklists, out error);
                }

                var successCnt = entities.Count(entity => entity.IsValid);

                context.BulkInsert(entities);
                context.MySaveChanges();

                scope.Complete();

                string message = successCnt == list.Count
                    ? string.Format("上傳簡訊接收者成功,總共上傳{0}筆資料", list.Count)
                    : string.Format("上傳簡訊接收者成功,總共上傳{0}筆資料({1}筆有效,{2}筆無效)", list.Count, successCnt, list.Count - successCnt);

                var result = new UploadedMessageReceiverListResult
                {
                    FileName          = uploadedFile.FileName,
                    Message           = message,
                    ValidCount        = successCnt,
                    InvalidCount      = list.Count - successCnt,
                    UploadedSessionId = uploadedFile.Id,
                };

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }
Пример #4
0
        protected override async Task DoUpdate(BlacklistModel model, int id, Blacklist entity)
        {
            entity.E164Mobile      = MobileUtil.GetE164PhoneNumber(model.Mobile);
            entity.Region          = MobileUtil.GetRegionName(model.Mobile);
            entity.UpdatedTime     = DateTime.UtcNow;
            entity.UpdatedUserName = CurrentUserName;

            await context.UpdateAsync(entity);
        }
        private ActionResult HandleUploadedFile_20160513(List <UploadedBlacklist> list, UploadedFile uploadedFile)
        {
            using (var scope = this.unitOfWork.CreateTransactionScope())
            {
                var repository = this.unitOfWork.Repository <Blacklist>();

                var successCnt = 0;

                foreach (var model in list)
                {
                    if (string.IsNullOrEmpty(model.Mobile))
                    {
                        continue;
                    }

                    var entity = new Blacklist();
                    entity.Name            = model.Name;
                    entity.Mobile          = model.Mobile;
                    entity.E164Mobile      = MobileUtil.GetE164PhoneNumber(model.Mobile);
                    entity.Region          = MobileUtil.GetRegionName(model.Mobile);
                    entity.Enabled         = true;
                    entity.Remark          = model.Remark;
                    entity.UpdatedTime     = uploadedFile.CreatedTime;
                    entity.CreatedUserId   = CurrentUserId;
                    entity.UpdatedUserName = CurrentUserName;
                    entity.UploadedFile    = uploadedFile;

                    var error   = string.Empty;
                    var isValid = this.validationService.Validate(entity, out error);

                    if (isValid)
                    {
                        entity = repository.Insert(entity);
                        successCnt++;
                    }
                }

                scope.Complete();

                string message = successCnt == list.Count
                    ? string.Format("上傳黑名單成功,總共上傳{0}筆資料", list.Count)
                    : string.Format("上傳黑名單成功,總共上傳{0}筆資料({1}筆成功,{2}筆失敗)", list.Count, successCnt, list.Count - successCnt);

                var result = new FileUploadResult
                {
                    FileName = uploadedFile.FileName,
                    Message  = message,
                };

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }
        protected override async Task <Contact> DoCreate(ContactModel model, Contact entity)
        {
            entity = new Contact();

            entity.Name          = model.Name;
            entity.Mobile        = model.Mobile;
            entity.E164Mobile    = MobileUtil.GetE164PhoneNumber(model.Mobile);
            entity.Region        = MobileUtil.GetRegionName(model.Mobile);
            entity.HomePhoneArea = model.HomePhoneArea;

            entity.HomePhone        = model.HomePhone;
            entity.CompanyPhoneArea = model.CompanyPhoneArea;
            entity.CompanyPhone     = model.CompanyPhone;
            entity.CompanyPhoneExt  = model.CompanyPhoneExt;
            entity.Email            = model.Email;

            entity.Msn          = model.Msn;
            entity.Description  = model.Description;
            entity.Birthday     = model.Birthday;
            entity.ImportantDay = model.ImportantDay;
            entity.Gender       = model.Gender;

            entity.Groups        = Group.CommonContactGroupName;
            entity.CreatedUserId = CurrentUserId;

            entity = await context.InsertAsync(entity);

            var group = context.Set <Group>()
                        .Where(p => p.Name == Group.CommonContactGroupName && p.CreatedUserId == CurrentUserId)
                        .FirstOrDefault();

            if (group == null)
            {
                throw new Exception(string.Format("使用者{0}常用聯絡人群組尚未建立", CurrentUserName));
            }

            var groupContact = new GroupContact();

            groupContact.GroupId   = group.Id;
            groupContact.ContactId = entity.Id;
            groupContact           = await context.InsertAsync(groupContact);

            return(entity);
        }
Пример #7
0
        protected override async Task <Blacklist> DoCreate(BlacklistModel model, Blacklist entity)
        {
            entity = new Blacklist();

            entity.Name       = model.Name;
            entity.Mobile     = model.Mobile;
            entity.E164Mobile = MobileUtil.GetE164PhoneNumber(model.Mobile);
            entity.Region     = MobileUtil.GetRegionName(model.Mobile);
            entity.Enabled    = model.Enabled;

            entity.Remark          = model.Remark;
            entity.UpdatedTime     = DateTime.UtcNow;
            entity.CreatedUserId   = CurrentUserId;
            entity.UpdatedUserName = CurrentUserName;

            entity = await context.InsertAsync(entity);

            return(entity);
        }
        private ActionResult HandleUploadedFile(List <UploadedBlacklist> list, UploadedFile uploadedFile)
        {
            using (var scope = this.unitOfWork.CreateTransactionScope())
            {
                var entities = list.Select((model, i) => new Blacklist
                {
                    Name            = model.Name,
                    Mobile          = model.Mobile,
                    E164Mobile      = MobileUtil.GetE164PhoneNumber(model.Mobile),
                    Region          = MobileUtil.GetRegionName(model.Mobile),
                    Enabled         = true,
                    Remark          = model.Remark,
                    UpdatedTime     = uploadedFile.CreatedTime,
                    CreatedUserId   = CurrentUserId,
                    UpdatedUserName = CurrentUserName,
                    UploadedFile    = uploadedFile,
                }).ToList(); // 要加上 ToList,否則會檢驗呈無效名單,目前不知道為什麼

                var error = string.Empty;
                entities = entities.Where(entity => this.validationService.Validate(entity, out error)).ToList();

                var successCnt = entities.Count;

                context.BulkInsert(entities);
                context.MySaveChanges();

                scope.Complete();

                string message = successCnt == list.Count
                    ? string.Format("上傳黑名單成功,總共上傳{0}筆資料", list.Count)
                    : string.Format("上傳黑名單成功,總共上傳{0}筆資料({1}筆成功,{2}筆失敗)", list.Count, successCnt, list.Count - successCnt);

                var result = new FileUploadResult
                {
                    FileName = uploadedFile.FileName,
                    Message  = message,
                };

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }
Пример #9
0
        protected override async Task <UploadedMessageReceiver> DoCreate(UploadedMessageReceiverModel model, UploadedMessageReceiver entity)
        {
            entity                      = new UploadedMessageReceiver();
            entity.RowNo                = context.Set <UploadedMessageReceiver>().Count(p => p.UploadedSessionId == model.UploadedSessionId) + 1;
            entity.Name                 = model.Name;
            entity.Mobile               = model.Mobile;
            entity.E164Mobile           = MobileUtil.GetE164PhoneNumber(model.Mobile);
            entity.Region               = MobileUtil.GetRegionName(model.Mobile);
            entity.Email                = model.Email;
            entity.SendTime             = Converter.ToUniversalTime(model.SendTimeString, Converter.yyyyMMddHHmm, ClientTimezoneOffset);
            entity.ClientTimezoneOffset = ClientTimezoneOffset;

            //entity.IsValid = model.IsValid; // 經由 this.validationHelper.Validate
            //entity.InvalidReason = model.InvalidReason; // 經由 this.validationHelper.Validate
            entity.UseParam          = model.UseParam;
            entity.Param1            = model.Param1 ?? string.Empty;
            entity.Param2            = model.Param2 ?? string.Empty;
            entity.Param3            = model.Param3 ?? string.Empty;
            entity.Param4            = model.Param4 ?? string.Empty;
            entity.Param5            = model.Param5 ?? string.Empty;
            entity.CreatedUserId     = CurrentUserId;
            entity.CreatedTime       = DateTime.UtcNow;
            entity.UploadedFile      = null;
            entity.UploadedSessionId = model.UploadedSessionId;

            var error      = string.Empty;
            var blacklists = context.Set <Blacklist>().Where(p => p.CreatedUserId == CurrentUserId).ToList();
            var isValid    = this.validationService.Validate(entity, blacklists, out error);

            // 目前就算驗證不過也沒關係,仍然可以存檔
            entity = await context.InsertAsync(entity);

            if (isValid)
            {
                return(entity);
            }
            else
            {
                throw new Exception(error);
            }
        }
Пример #10
0
        public void Case2()
        {
            //return;

            string mobile = "0928873075";

            try
            {
                foreach (var fmt in new PhoneNumberFormat[] {
                    //PhoneNumberFormat.INTERNATIONAL,
                    //PhoneNumberFormat.NATIONAL,
                    PhoneNumberFormat.E164
                })
                {
                    string formattedNumber = MobileUtil.Format(mobile, fmt);

                    formattedNumber = formattedNumber.Replace("+", string.Empty);

                    string userName = "******";
                    string password = "******";

                    var configuration = new Configuration(userName, password);
                    var SMSClient     = new SMSClient(configuration);

                    var SMSRequest = new SMSRequest(userName, formattedNumber, new string[] { formattedNumber });

                    //SendMessageResult sendMessageResult = SMSClient.SmsMessagingClient.SendSMS(SMSRequest);

                    //string requestId = sendMessageResult.ClientCorrelator; // you can use this to get deliveryReportList later.


                    //Console.WriteLine(formattedNumber);
                    //Console.WriteLine(requestId);
                }
            }
            catch
            {
                throw;
            }
        }
Пример #11
0
        protected override async Task DoUpdate(UploadedMessageReceiverModel model, int id, UploadedMessageReceiver entity)
        {
            entity.SendTime             = Converter.ToUniversalTime(model.SendTimeString, Converter.yyyyMMddHHmm, ClientTimezoneOffset);
            entity.ClientTimezoneOffset = ClientTimezoneOffset;

            entity.E164Mobile    = MobileUtil.GetE164PhoneNumber(model.Mobile);
            entity.Region        = MobileUtil.GetRegionName(model.Mobile);
            entity.CreatedUserId = entity.CreatedUserId;

            var error      = string.Empty;
            var blacklists = context.Set <Blacklist>().Where(p => p.CreatedUserId == CurrentUserId).ToList();
            var isValid    = this.validationService.Validate(entity, blacklists, out error);

            // 目前就算驗證不過也沒關係,仍然可以存檔
            await context.UpdateAsync(entity);

            if (isValid)
            {
            }
            else
            {
                throw new Exception(error);
            }
        }
        private ActionResult HandleUploadedFile(List <UploadedContact> list, UploadedFile uploadedFile)
        {
            // TODO: 批次新增

            using (var scope = this.unitOfWork.CreateTransactionScope())
            {
                var repository = this.unitOfWork.Repository <Contact>();

                var successCnt = 0;

                foreach (var model in list)
                {
                    // 姓名以及行動電話必填
                    if (string.IsNullOrEmpty(model.Name))
                    {
                        continue;
                    }
                    if (string.IsNullOrEmpty(model.Mobile))
                    {
                        continue;
                    }

                    var entity = new Contact();
                    entity.Name         = model.Name;
                    entity.Mobile       = model.Mobile;
                    entity.E164Mobile   = MobileUtil.GetE164PhoneNumber(model.Mobile);
                    entity.Region       = MobileUtil.GetRegionName(model.Mobile);
                    entity.HomePhone    = model.HomePhone;
                    entity.CompanyPhone = model.CompanyPhone;
                    entity.Email        = model.Email;
                    entity.Msn          = model.Msn;
                    entity.Description  = model.Description;
                    entity.Birthday     = model.Birthday;
                    entity.ImportantDay = model.ImportantDay;
                    entity.Gender       = model.Gender == "2" ? Gender.Female :
                                          model.Gender == "1" ? Gender.Male : Gender.Unknown;
                    entity.CreatedUserId = CurrentUserId;

                    var error   = string.Empty;
                    var isValid = this.validationService.Validate(entity, out error);

                    if (isValid)
                    {
                        entity = repository.Insert(entity);

                        string groupDescription = model.Group.Trim();
                        if (!string.IsNullOrEmpty(groupDescription))
                        {
                            var group = this.unitOfWork.Repository <Group>().DbSet
                                        .Where(p => p.CreatedUserId == CurrentUserId && p.Name == model.Group.Trim())
                                        .FirstOrDefault();
                            if (group != null)
                            {
                                this.unitOfWork.Repository <GroupContact>().Insert(new GroupContact
                                {
                                    GroupId   = group.Id,
                                    ContactId = entity.Id
                                });
                            }
                        }

                        successCnt++;
                    }
                }

                scope.Complete();

                string message = successCnt == list.Count
                    ? string.Format("上傳聯絡人成功,總共上傳{0}筆資料", list.Count)
                    : string.Format("上傳聯絡人成功,總共上傳{0}筆資料({1}筆成功,{2}筆失敗)", list.Count, successCnt, list.Count - successCnt);

                var result = new FileUploadResult
                {
                    FileName = uploadedFile.FileName,
                    Message  = message,
                };

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }
        protected override IQueryable <SendMessageStatistic> DoGetList(MemberSendMessageStatisticCriteriaModel criteria)
        {
            var predicate = PredicateBuilder.True <SendMessageStatistic>();

            predicate = predicate.And(p => p.CreatedUserId == CurrentUserId);
            predicate = predicate.And(p => p.SendTime >= criteria.StartDate);
            predicate = predicate.And(p => p.SendTime <= criteria.EndDate);

            if (!string.IsNullOrEmpty(criteria.Mobile) ||
                !string.IsNullOrEmpty(criteria.ReceiptStatus))
            {
                var innerPredicate = PredicateBuilder.True <SendMessageHistory>();
                innerPredicate = innerPredicate.And(p => p.CreatedUserId == CurrentUserId);
                innerPredicate = innerPredicate.And(p => p.SendTime >= criteria.StartDate);
                innerPredicate = innerPredicate.And(p => p.SendTime <= criteria.EndDate);

                if (!string.IsNullOrEmpty(criteria.Mobile))
                {
                    var _predicate = PredicateBuilder.False <SendMessageHistory>();

                    var arrMobile = criteria.Mobile.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);

                    if (arrMobile.Length != 0)
                    {
                        foreach (string mobile in arrMobile)
                        {
                            string mobileKeyword = mobile;

                            if (MobileUtil.IsPossibleNumber(mobileKeyword))
                            {
                                mobileKeyword = MobileUtil.GetE164PhoneNumber(mobileKeyword);
                            }

                            _predicate = _predicate.Or(p => p.DestinationAddress.Contains(mobileKeyword));
                        }

                        innerPredicate = innerPredicate.And(_predicate);
                    }
                }

                if (!string.IsNullOrEmpty(criteria.ReceiptStatus))
                {
                    var _predicate = PredicateBuilder.False <SendMessageHistory>();

                    var arrReceiptStatus = criteria.ReceiptStatus.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);

                    if (arrReceiptStatus.Length != 0)
                    {
                        foreach (string receiptStatus in arrReceiptStatus)
                        {
                            var status = (DeliveryReportStatus)Convert.ToInt32(receiptStatus);
                            _predicate = _predicate.Or(p => p.DeliveryStatus == status);
                        }

                        innerPredicate = innerPredicate.And(_predicate);
                    }
                }

                var sendMessageQueueIds = context.Set <SendMessageHistory>()
                                          .AsExpandable()
                                          .Where(innerPredicate)
                                          .Select(p => p.SendMessageQueueId)
                                          .Distinct()
                                          .ToList();

                predicate = predicate.And(p => sendMessageQueueIds.Contains(p.SendMessageQueueId)); // 20151126 Norman, 避免StackOverFlow
            }

            // 目前使用者的資料
            var result = context.Set <SendMessageStatistic>()
                         .AsExpandable()
                         .Where(predicate)
                         .OrderByDescending(p => p.Id);

            return(result);
        }