コード例 #1
0
ファイル: CrowFoundMgr.cs プロジェクト: meloht/yihuiServer
        public bool SaveCrowFound(crowd_funding crowdFunding, List <cf_type> cfTypes, List <cf_label> labels)
        {
            using (userEntities userEntities = new userEntities())
            {
                using (var tran = userEntities.Database.BeginTransaction())
                {
                    try
                    {
                        crowdFunding.cf_fund_amount = 0;
                        crowdFunding.support_amount = 0;
                        userEntities.crowd_funding.Add(crowdFunding);
                        int iRent = userEntities.SaveChanges();
                        if (iRent > 0)
                        {
                            foreach (var item in cfTypes)
                            {
                                item.cf_id = crowdFunding.id;
                            }
                            userEntities.cf_type.AddRange(cfTypes);


                            foreach (var item in labels)
                            {
                                item.cf_id = crowdFunding.id;
                            }
                            userEntities.cf_label.AddRange(labels);

                            userEntities.SaveChanges();
                        }

                        tran.Commit();
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        tran.Rollback();
                        Trace.WriteLine(ex);
                    }
                }
            }
            return(false);
        }
コード例 #2
0
        private void ButtonAdd_OnClick(object sender, RoutedEventArgs e)
        {
            if (IsCheckInput() == false)
            {
                return;
            }
            crowd_funding crowdFunding = new crowd_funding();

            if (TextBeginDate.Value.HasValue)
            {
                crowdFunding.cf_begin_time = HelpFunction.ConvertToTimestamp(TextBeginDate.Value.Value);
            }
            category category = TextArtType.GetCategory();

            if (category != null)
            {
                crowdFunding.cf_category = category.fc_id;
            }

            crowdFunding.cf_city_id      = this.CityControl.GetCity().city_id;
            crowdFunding.cf_created_time = HelpFunction.ConvertToTimestamp(DateTime.Now);
            crowdFunding.cf_desc         = this.TextServiceIntro.HtmlContent;
            if (TextEndDate.Value.HasValue)
            {
                crowdFunding.cf_end_time = HelpFunction.ConvertToTimestamp(this.TextEndDate.Value.Value);
            }

            crowdFunding.cf_front_icon = this.TextFrontImg.GetUrl();

            if (this.TextServiceCost.Value.HasValue)
            {
                crowdFunding.cf_fund_end = (decimal)this.TextServiceCost.Value.Value;
            }
            crowdFunding.cf_name            = this.TextCrowName.Text.Trim();
            crowdFunding.cf_note            = this.TextNote.HtmlContent;
            crowdFunding.cf_owner_id        = this.TextActor.SelectActor.UserId;
            crowdFunding.cf_province_id     = this.CityControl.GetProvince().province_id;
            crowdFunding.cf_service_address = this.TextAddress.Text.Trim();

            crowdFunding.cf_service_duration = this.TextServiceDuration.Value;
            if (TextServiceTime.Value.HasValue)
            {
                crowdFunding.cf_service_time = HelpFunction.ConvertToTimestamp(this.TextServiceTime.Value.Value);
            }


            var sc = TextArtType.GetSecondCategory();

            if (sc != null)
            {
                crowdFunding.cf_second_category = sc.cs_id;
            }
            var tc = TextArtType.GetThirdCategory();

            if (tc != null)
            {
                crowdFunding.cf_third_category = tc.ct_id;
            }

            crowdFunding.cf_state = 0;

            List <cf_type> listTypes = new List <cf_type>();

            listTypes.Add(TextCrowDetail.DefaultCfType());
            foreach (var item in TextCrowDetail.CtTypes)
            {
                listTypes.Add(item);
            }

            List <cf_label> listTag = new List <cf_label>();

            if (!string.IsNullOrEmpty(this.ArtTags.Label1.Trim()))
            {
                listTag.Add(new cf_label()
                {
                    label_text = ArtTags.Label1.Trim()
                });
            }
            if (!string.IsNullOrEmpty(this.ArtTags.Label2.Trim()))
            {
                listTag.Add(new cf_label()
                {
                    label_text = ArtTags.Label2.Trim()
                });
            }
            if (!string.IsNullOrEmpty(this.ArtTags.Label3.Trim()))
            {
                listTag.Add(new cf_label()
                {
                    label_text = ArtTags.Label3.Trim()
                });
            }
            if (RadioButtonImg.IsChecked.HasValue && RadioButtonImg.IsChecked.Value)
            {
                crowdFunding.cf_front_icon_type = 0;
            }
            else
            {
                crowdFunding.cf_front_icon_type = 1;
            }

            if (TextFrontImg.UploadType == FileTypeDirEnum.CrowdFundVideoDir)
            {
                string img = "";
                bool   bll = ServerFileMgr.GetVideoThumbnailImg(FileTypeDirEnum.CrowdFundVideoDir, TextFrontImg.ServerKey, out img);
                if (bll)
                {
                    crowdFunding.cf_video_thumbnail = img;
                }
            }

            bool bl = CrowFoundMgr.Instance.SaveCrowFound(crowdFunding, listTypes, listTag);

            if (bl)
            {
                MessageBox.Show("保存成功");
                this.DialogResult = true;
            }
            else
            {
                DisposeData();
                MessageBox.Show("保存失败");
                this.DialogResult = false;
            }
        }