示例#1
0
        /// <summary>
        /// 作者:Kylin
        /// 时间:2014.1.23
        /// 描述:添加问卷详情 
        /// </summary>
        /// <param name="branchId"></param>
        /// <param name="subject"></param>
        /// <param name="platformtype"></param>
        /// <param name="beginTime"></param>
        /// <param name="endTime"></param>
        /// <param name="surveyItems"></param>
        /// <param name="remark"></param>
        /// <returns></returns>
        public static bool CreateSurvey(string branchId, string subject, int? platformtype, bool isPopup, DateTime beginTime, DateTime endTime, List<SurveyItemsModel> surveyItems, string remark, int loginUserId)
        {
            using (var tran = new TransactionScope())
            {
                using (var edb = new EmeEntities())
                {
                    try
                    {
                        var survey = new Survey()
                        {
                            PlatformType = platformtype,
                            IsPopup = isPopup,
                            Subject = subject,
                            IsRights = true,
                            BeginTime = beginTime,
                            EndTime = endTime,
                            Remark = remark,
                            Status = ConvertEnum.StatusTypeForActive,
                            UpdateTime = DateTime.Now
                        };

                        edb.Entry(survey).State = EntityState.Added;
                        edb.SaveChanges();

                        foreach (var addItem in surveyItems)
                        {
                            var surveyItem = new SurveyItem()
                            {
                                Title = addItem.title,
                                Status = ConvertEnum.StatusTypeForActive,
                                SurveyId = survey.Id,
                                IsMultiple = addItem.IsMulti,
                                CreateTime = DateTime.Now
                            };

                            edb.Entry(surveyItem).State = EntityState.Added;
                            edb.SaveChanges();

                            foreach (var addOption in addItem.Options)
                            {
                                var surveyItemOption = new SurveyItemOption()
                                {
                                    Title = addOption.title,
                                    Status = ConvertEnum.StatusTypeForActive,
                                    SurveyItemId = surveyItem.Id,
                                    CreateTime = DateTime.Now
                                };

                                edb.Entry(surveyItemOption).State = EntityState.Added;
                            }
                        }

                        if (branchId.Trim() != "")
                        {
                            var branchIdList = branchId.Split(',');
                            foreach (var bid in branchIdList)
                            {
                                var surveyRights = new SurveyRights()
                                {
                                    SurveyId = survey.Id,
                                    BranchId = Convert.ToInt32(bid),
                                    Status = ConvertEnum.StatusTypeForActive,
                                    CreateTime = DateTime.Now
                                };
                                edb.Entry(surveyRights).State = EntityState.Added;
                            }
                        }
                        var result = edb.SaveChanges() > 0;
                        tran.Complete();

                        return result;
                    }
                    catch (Exception ex)
                    {
                        tran.Dispose();
                        Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs()
                        {
                            ExceptionType = CommonHelper.To<int>(ExceptionType.Message),
                            Message = string.Format("SurveyBLL-CreateSurvey:{0};{1};{2}", ex.Message, ex.InnerException, ex.HelpLink),
                            IsTreat = false,
                            CreateBy = loginUserId,
                            CreateTime = DateTime.Now
                        });
                        return false;
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// 作者:Kylin
        /// 时间:2014.1.14
        /// 描述:添加问卷详情
        /// -------------------------------------
        /// 作者:Vincen
        /// 时间:2014.04.01
        /// 描述:更新调查问卷
        /// </summary>
        /// <param name="surveyId"></param>
        /// <param name="subject"></param>
        /// <param name="platformtype"></param>
        /// <param name="beginTime"></param>
        /// <param name="endTime"></param>
        /// <param name="surveyItems"></param>
        /// <param name="remark"></param>
        public static bool UpdateSurvey(int surveyId, string subject, int? platformtype, DateTime beginTime, DateTime endTime, List<SurveyItemsModel> surveyItems, string remark, int loginUserId)
        {
            using (var edb = new EmeEntities())
            {
                using (var tran = new TransactionScope())
                {
                    try
                    {
                        // 更新 Survey
                        var model = edb.Survey.SingleOrDefault(p => p.Id == surveyId);
                        if (model != null)
                        {
                            model.PlatformType = platformtype;
                            model.BeginTime = beginTime;
                            model.EndTime = endTime;
                            model.Subject = subject;
                            model.Remark = remark;
                            model.UpdateTime = DateTime.Now;

                            edb.Entry(model).State = EntityState.Modified;
                        }

                        var surveyItemList = edb.SurveyItem.Where(p => p.SurveyId == surveyId);

                        // 删除原有 SurveyItem
                        foreach (var item in surveyItemList)
                        {
                            item.Status = ConvertEnum.StatusTypeForDelete;
                            foreach (var option in item.SurveyItemOption)
                            {
                                option.Status = ConvertEnum.StatusTypeForDelete;

                                edb.Entry(option).State = EntityState.Modified;
                            }

                            edb.Entry(item).State = EntityState.Modified;
                        }

                        // 新增更改 SurveyItem
                        foreach (var item in surveyItems)
                        {
                            var surveyItem = new SurveyItem()
                            {
                                Title = item.title,
                                Status = ConvertEnum.StatusTypeForActive,
                                SurveyId = surveyId,
                                IsMultiple = item.IsMulti,
                                CreateTime = DateTime.Now,
                            };

                            edb.Entry(surveyItem).State = EntityState.Added;
                            edb.SaveChanges();

                            foreach (var option in item.Options)
                            {
                                var surveyItemOption = new SurveyItemOption()
                                {
                                    Title = option.title,
                                    Status = ConvertEnum.StatusTypeForActive,
                                    SurveyItemId = surveyItem.Id,
                                    CreateTime = DateTime.Now
                                };

                                edb.Entry(surveyItemOption).State = EntityState.Added;
                            }
                        }

                        var result = edb.SaveChanges() > 0;
                        tran.Complete();

                        return result;
                    }
                    catch (Exception ex)
                    {
                        tran.Dispose();
                        Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs()
                        {
                            ExceptionType = CommonHelper.To<int>(ExceptionType.Message),
                            Message = string.Format("SurveyBLL-UpdateSurvey:{0};{1};{2}", ex.Message, ex.InnerException, ex.HelpLink),
                            IsTreat = false,
                            CreateBy = loginUserId,
                            CreateTime = DateTime.Now
                        });
                        return false;
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// 作者:Kylin
        /// 时间:2014.1.23
        /// 描述:添加问卷详情
        /// ------------------------------
        /// 作者:Vincen
        /// 时间:2014.04.01
        /// 描述:新半
        /// </summary>
        /// <param name="surveyItemId">问卷详情实体</param>
        /// <param name="titles">问卷项标题,问卷项标题,</param>
        /// <param name="loginUserId"></param>
        /// <returns></returns>
        public static bool CreateSurveyItemOption(int surveyItemId, string titles, int loginUserId)
        {
            using (var edb = new EmeEntities())
            {
                try
                {
                    //删除选项
                    var surveyItemOptionList = edb.SurveyItemOption.Where(p => p.SurveyItemId == surveyItemId);
                    foreach (var option in surveyItemOptionList)
                    {
                        option.Status = ConvertEnum.StatusTypeForDelete;
                        edb.Entry(option).State = EntityState.Modified;
                    }

                    var titleArray = titles.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);

                    foreach (var str in titleArray)
                    {
                        if (edb.SurveyItemOption.Any(p => p.Title == str && p.SurveyItemId == surveyItemId))
                        {
                            var title = str;
                            var optionList =
                                edb.SurveyItemOption.Where(
                                    p => p.Title == title && p.SurveyItemId == surveyItemId);
                            foreach (var item in optionList)
                            {
                                item.Status = ConvertEnum.StatusTypeForActive;

                                edb.Entry(item).State = EntityState.Modified;
                            }
                        }
                        else
                        {
                            var option = new SurveyItemOption()
                            {
                                Title = str,
                                Status = ConvertEnum.StatusTypeForActive,
                                SurveyItemId = surveyItemId
                            };

                            edb.Entry(option).State = EntityState.Added;
                        }
                    }

                    var result = edb.SaveChanges() > 0;
                    return result;
                }
                catch (Exception ex)
                {
                    Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs()
                    {
                        ExceptionType = CommonHelper.To<int>(ExceptionType.Message),
                        Message = string.Format("SurveyBLL-CreateSurveyItemOption:{0};{1};{2}", ex.Message, ex.InnerException, ex.HelpLink),
                        IsTreat = false,
                        CreateBy = loginUserId,
                        CreateTime = DateTime.Now
                    });
                    return false;
                }
            }
        }