예제 #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
        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));
            }
        }