コード例 #1
0
ファイル: UserArticleController.cs プロジェクト: kin0428/Splg
        public ActionResult AddNewArticle(long newsClassID, long quoteUniqueId1, long? quoteUniqueId2, long? quoteUniqueId3)
        {
            //Todo:認証処理 AOPでやりたい。 一旦Session変数を参照し判定
            if (Session["CurrentUser"] == null)
            {
                return RedirectToActionPermanent("Login", "Member", new { area = "" });
            }

            var userArticleInfoViewModel = new UserArticleInfoViewModel();
            userArticleInfoViewModel.NewsClassId = newsClassID;
            userArticleInfoViewModel.QuoteUniqueId1 = quoteUniqueId1;
            userArticleInfoViewModel.QuoteUniqueId2 = quoteUniqueId2 ?? 0;
            userArticleInfoViewModel.QuoteUniqueId3 = quoteUniqueId3 ?? 0;
            userArticleInfoViewModel.Status = 1;
            userArticleInfoViewModel.Title = string.Empty;
            userArticleInfoViewModel.Body = string.Empty;
            userArticleInfoViewModel.ImageLink = UserArticleInfoViewModel.DefaultImageLink;

            userArticleInfoViewModel = AppliedDetailContent(userArticleInfoViewModel);

            return View(userArticleInfoViewModel);
        }
コード例 #2
0
ファイル: UserArticleController.cs プロジェクト: kin0428/Splg
 public UserArticleInfoViewModel AppliedDetailContent(UserArticleInfoViewModel input)
 {
     UserArticleInfoViewModel model = input;
     switch (model.NewsClassId)
     {
         case 1:
             model.NewsInfo = (from brief in memberContext.BriefNews
                               join photo in memberContext.PhotoNews on brief.NewsItemID equals photo.NewsItemID into br_photo
                               from tmp in br_photo.DefaultIfEmpty()
                               where (brief.Status == Constants.NEWS_VALID_STATUS && brief.CarryLimitDate >= DateTime.Now)
                               select new NewsInfoViewModel
                               {
                                   NewsItemID = brief.NewsItemID,
                                   DeliveryDate = brief.DeliveryDate,
                                   Headline = brief.Headline,
                                   newstext = brief.newstext,
                                   SentFrom = brief.SentFrom,
                                   Duid = tmp.Duid,
                                   Content = tmp.Content,
                                   SubHeadline = brief.SubHeadline,
                               } into news_photo
                               where (news_photo.NewsItemID == model.QuoteUniqueId1
                                 && (news_photo.Duid == Constants.IMAGE_DUID || news_photo.Duid == null))
                               select news_photo).FirstOrDefault();
             if (model.SportID <= 0)
             {
                 var sportTopic = (from bn in memberContext.BriefNews
                                   join nt in memberContext.NewsTopic on bn.NewsItemID equals nt.NewsItemID
                                   join tm in memberContext.TopicMaster on nt.TopicID equals tm.TopicID
                                   where bn.NewsItemID == model.QuoteUniqueId1 && tm.ClassificationType == 1
                                   select tm).FirstOrDefault();
                 if (sportTopic != null)
                     model.SportID = sportTopic.SportID;
             }
             break;
         case 2:
             switch (model.QuoteUniqueId1)
             {
                 case 1: // NPB
                     model.NpbTeamInfo = (new NpbTeamInfoTeamTopController()).GetTeamInfo(Convert.ToInt32(model.QuoteUniqueId3));
                     break;
                 case 2: //JLeague
                     int jType = 0;
                     var teamID = Convert.ToInt32(model.QuoteUniqueId3);
                     if (Session["JType"] != null)
                     {
                         jType = Convert.ToInt32(Session["JType"].ToString());
                     }
                     else
                     {
                         jType = GetJlgTypeByTeamId(teamID);
                     }
                     int gameKindID = 0;
                     switch (jType)
                     {
                         case 1:
                             gameKindID = 2;
                             break;
                         case 2:
                             gameKindID = 6;
                             break;
                     }
                     model.JlgTeamInfo = (new JlgTeamInfoTopController()).GetTeamInfo(teamID, gameKindID);
                     JlgEntities jlg = new JlgEntities();
                     model.RankInfoRT = (from r in jlg.RankInfoRT where r.TeamID == teamID select r).FirstOrDefault();
                     break;
                 case 3: //MLB
                     model.MlbTeamInfo = (new MlbTeamInfoTeamTopController()).GetTeamInfo(Convert.ToInt32(model.QuoteUniqueId3));
                     break;
                 case 4:
                     break;
             }
             break;
         case 3:
             switch (model.QuoteUniqueId1)
             {
                 case 1: //Npb
                     break;
                 case 2: //Jleague
                     var teamID = Convert.ToInt32(model.QuoteUniqueId2);
                     var playerID = Convert.ToInt32(model.QuoteUniqueId3);
                     model.PlayerInfoYear = (new JlgTeamInfoPlayerDetailController()).GetPlayerInfo(teamID, playerID);
                     model.PlayerSum = (new JlgTeamInfoPlayerDetailController()).GetPlayerInfo_Sum(teamID, playerID);
                     break;
                 case 3: //Mlb
                     model.MlbTeamInfo = (new MlbTeamInfoTeamTopController()).GetTeamInfo(Convert.ToInt32(model.QuoteUniqueId2));
                     break;
             }
             break;
         case 6:
             ViewBag.Year = model.QuoteUniqueId2 / 100;
             ViewBag.Month = model.QuoteUniqueId2 % 100;
             //ViewBag.NumType = model.QuoteUniqueId3;
             //ViewBag.OrtherMemberId = model.QuoteUniqueId1;
             break;
     }
     model.RelatedTopicList = GetRelatedTopicofAPost(model.NewsClassId, model.QuoteUniqueId1, model.QuoteUniqueId2, model.QuoteUniqueId3);
     return model;
 }
コード例 #3
0
ファイル: UserArticleController.cs プロジェクト: kin0428/Splg
        public ActionResult EditNewUserArticle(UserArticleInfoViewModel model)
        {
            model = AppliedDetailContent(model);
            if (model.ContributeId > 0)
            {
                var article = from a in memberContext.Contribution
                              where a.ContributeId == model.ContributeId
                              select a;
                if (article != null)
                {
                    if (string.IsNullOrEmpty(model.OldImageLink) && !string.IsNullOrEmpty(model.ImageLink) && !model.ImageLink.Contains("dummy_2.png"))
                    {
                        string imagePath = "\\Content\\img\\upload\\contribution\\";
                        string tempImagePath = "\\Content\\img\\upload\\contribution\\tmp_dir\\";
                        string rootPath = Server.MapPath("~");
                        string tempFilePath = Path.GetFullPath(rootPath + tempImagePath);
                        string filePath = Path.GetFullPath(rootPath + imagePath);
                        string fileName = "";
                        try
                        {
                            if (!System.IO.Directory.Exists(tempFilePath))
                                System.IO.Directory.CreateDirectory(tempFilePath);

                            fileName = model.ImageLink.Split('/').Last();
                            if (!string.IsNullOrEmpty(fileName) && System.IO.File.Exists(filePath + fileName))
                            {
                                System.IO.File.Copy(filePath + fileName, tempFilePath + fileName);
                                model.ImageLink = @"~/Content/img/upload/contribution/tmp_dir/" + fileName;
                                model.OldImageLink = fileName;
                                model.ImageName = fileName;
                            }

                        }
                        catch
                        {
                            fileName = "";
                        }
                    }
                }
            }
            return View(model);
        }
コード例 #4
0
ファイル: UserArticleController.cs プロジェクト: kin0428/Splg
 public ActionResult EditNewUserArticle()
 {
     if (Session["CurrentUser"] == null)
     {
         return RedirectToAction("Login", "Member");
     }
     else
     {
         UserArticleInfoViewModel model = new UserArticleInfoViewModel();
         if (string.IsNullOrEmpty(model.Title))
         {
             return RedirectToAction("Index", "Home");
         }
         else
         {
             return View();
         }
     }
 }
コード例 #5
0
ファイル: UserArticleController.cs プロジェクト: kin0428/Splg
        public ActionResult DeleteNewUserArticle(UserArticleInfoViewModel model)
        {
            if (Session["CurrentUser"] == null)
            {
                return RedirectToAction("Login", "Member");
            }
            string rootPath = Server.MapPath("~");
            string tempImagePath = "\\Content\\img\\upload\\contribution\\tmp_dir\\";
            string tempFilePath = Path.GetFullPath(rootPath + tempImagePath);
            string imagePath = "\\Content\\img\\upload\\contribution\\";
            string filePath = Path.GetFullPath(rootPath + imagePath);
            try
            {
                if (System.IO.Directory.Exists(tempFilePath))
                    DeleteTemperaryDir(@"~/Content/img/upload/contribution/tmp_dir/");
            }
            catch
            {
                return View("Error");
            }
            bool transactionResult = false;
            if (model.ContributeId > 0)
            {
                Contribution record = (from c in memberContext.Contribution
                                       where c.ContributeId == model.ContributeId
                                       select c).FirstOrDefault();
                if (record != null)
                {
                    using (var newArticleTransaction = memberContext.Database.BeginTransaction())
                    {
                        var quoteTopics = from q in memberContext.QuotTopic
                                          where q.ContributeID == model.ContributeId
                                          select q;
                        var contributedOrgs = from co in memberContext.ContributionQuotOrg
                                              where co.ContributeId == model.ContributeId
                                              select co;

                        try
                        {
                            foreach (var qt in quoteTopics)
                            {
                                memberContext.QuotTopic.Remove(qt);
                            }
                            foreach (var cqo in contributedOrgs)
                            {
                                memberContext.ContributionQuotOrg.Remove(cqo);
                            }
                            memberContext.Contribution.Remove(record);
                            memberContext.SaveChanges();

                            newArticleTransaction.Commit();
                            transactionResult = true;
                        }
                        catch
                        {
                            transactionResult = false;
                            newArticleTransaction.Rollback();
                        }
                    }
                    if (transactionResult && !string.IsNullOrEmpty(model.OldImageLink))
                    {
                        if (System.IO.File.Exists(filePath + model.OldImageLink))
                        {
                            FileInfo f = new FileInfo(System.Web.Hosting.HostingEnvironment.MapPath(@"~/Content/img/upload/contribution/" + model.OldImageLink));
                            f.Delete();
                        }
                    }
                }
            }
            return RedirectToAction("Index");
        }
コード例 #6
0
ファイル: UserArticleController.cs プロジェクト: kin0428/Splg
        public ActionResult ConfirmUserArticle(UserArticleInfoViewModel model)
        {
            //Todo:認証処理 AOPでやりたい。 一旦Session変数を参照し判定
            if (Session["CurrentUser"] == null)
            {
                return RedirectToActionPermanent("Login", "Member", new { area = "" });
            }

            ViewBag.pageNO = "5-4-1";
            try
            {
                long memberID = Convert.ToInt64(Session["CurrentUser"]);
                string imageDataUrl = model.DataURL;
                string rootPath = Server.MapPath("~");
                //string imagePath = "\\Content\\img\\upload\\contribution\\";
                string tempImagePath = "\\Content\\img\\upload\\contribution\\tmp_dir\\";
                //string filePath = Path.GetFullPath(rootPath + imagePath);
                string tempFilePath = Path.GetFullPath(rootPath + tempImagePath);
                string fileName = "";
                try
                {
                    if (model.ContributeId <= 0 || string.IsNullOrEmpty(model.ImageLink) || !string.IsNullOrEmpty(model.DataURL))
                    {
                        if (!System.IO.Directory.Exists(tempFilePath))
                            System.IO.Directory.CreateDirectory(tempFilePath);
                        if (!string.IsNullOrEmpty(model.DataURL))
                        {
                            fileName = Utils.SaveImageToDirectory(imageDataUrl, tempFilePath);
                            model.ImageName = fileName;
                            if (!string.IsNullOrEmpty(fileName))
                            {
                                model.ImageLink = @"~/Content/img/upload/contribution/tmp_dir/" + fileName;
                            }
                        }
                        else
                        {
                            model.ImageLink = UserArticleInfoViewModel.DefaultImageLink;
                        }

                    }
                }
                catch
                {
                    fileName = "";
                }
                if (model.ContributeId <= 0)
                    model.ContributeDate = System.DateTime.Now;
                model.MemberId = memberID;
                model.Nickname = memberContext.Member.SingleOrDefault(m => m.MemberId == memberID).Nickname;
                //model.RelatedTopicsList = (UserArticleRelatedTopicViewModel)Session["RelatedTopic"];
                //Session["NewPost"] = model;
                model = AppliedDetailContent(model);
                return View(model);
                //}
            }
            catch
            {
                return View("Error");
            }
        }
コード例 #7
0
ファイル: UserArticleController.cs プロジェクト: kin0428/Splg
        public ActionResult ConfirmUserArticle()
        {
            //Todo:認証処理 AOPでやりたい。 一旦Session変数を参照し判定
            if (Session["CurrentUser"] == null)
            {
                return RedirectToActionPermanent("Login", "Member", new { area = "" });
            }

            var model = new UserArticleInfoViewModel();
            if (string.IsNullOrEmpty(model.Title))
            {
                return RedirectToAction("Index", "Home");
            }
            else
            {
                ViewBag.pageNO = "5-4-1";
                return View();
            }
        }
コード例 #8
0
ファイル: UserArticleController.cs プロジェクト: kin0428/Splg
        public ActionResult CompleteAddNewArticle(UserArticleInfoViewModel model)
        {
            //Todo:認証処理 AOPでやりたい。 一旦Session変数を参照し判定
            if (Session["CurrentUser"] == null)
            {
                return RedirectToActionPermanent("Login", "Member", new { area = "" });
            }

            ViewBag.pageNO = "5-4-2";
            bool transactionResult = true;
            List<QuotTopic> topicList = new List<QuotTopic>();
            Int64 memberId = Convert.ToInt64(Session["CurrentUser"].ToString());
            long newContributionID = 0;
            if (model != null)
            {
                if (model.ContributeId > 0)
                {
                    var article = (from a in memberContext.Contribution
                                   where a.ContributeId == model.ContributeId
                                   select a).FirstOrDefault();
                    if (article != null)
                    {
                        newContributionID = model.ContributeId;
                        if (ModelState.IsValid)
                        {
                            using (var newArticleTransaction = memberContext.Database.BeginTransaction())
                            {
                                try
                                {
                                    article.Title = model.Title;
                                    article.Body = model.Body;
                                    //article.MemberId = model.MemberId;
                                    if (!string.IsNullOrEmpty(model.ImageName))
                                    {
                                        article.ContributedPicture = @"~/Content/img/upload/contribution/" + model.ImageName;
                                    }
                                    //article.ContributeDate = model.ContributeDate;
                                    article.ModifiedDate = DateTime.Now;
                                    memberContext.Entry(article).State = EntityState.Modified;
                                    memberContext.SaveChanges();
                                    newArticleTransaction.Commit();
                                    transactionResult = true;
                                }
                                catch
                                {
                                    transactionResult = false;
                                    newArticleTransaction.Rollback();
                                }

                            }
                        }
                        if (transactionResult && !string.IsNullOrEmpty(model.OldImageLink))
                        {
                            string tempImagePath = "\\Content\\img\\upload\\contribution\\";
                            string rootPath = Server.MapPath("~");
                            string tempFilePath = Path.GetFullPath(rootPath + tempImagePath);
                            try
                            {
                                if (System.IO.File.Exists(tempFilePath + model.OldImageLink))
                                {
                                    FileInfo f = new FileInfo(System.Web.Hosting.HostingEnvironment.MapPath(@"~/Content/img/upload/contribution/" + model.OldImageLink));
                                    f.Delete();
                                }
                            }
                            catch
                            {
                                return View("Error");
                            }
                        }
                    }
                }
                else
                {
                    using (var newArticleTransaction = memberContext.Database.BeginTransaction())
                    {
                        try
                        {
                            var newContributeRow = new Contribution
                            {
                                Title = model.Title,
                                Body = model.Body,
                                MemberId = memberId,
                                ContributedPicture = @"~/Content/img/upload/contribution/" + model.ImageName,
                                ContributeDate = DateTime.Now,
                                ModifiedDate = DateTime.Now
                            };
                            memberContext.Contribution.Add(newContributeRow);
                            memberContext.SaveChanges();
                            newContributionID = newContributeRow.ContributeId;
                            var newContributeQuotRow = new ContributionQuotOrg
                            {
                                ContributeId = newContributeRow.ContributeId,
                                NewsClassId = model.NewsClassId,
                                QuoteUniqueId1 = model.QuoteUniqueId1,
                                QuoteUniqueId2 = model.QuoteUniqueId2,
                                QuoteUniqueId3 = model.QuoteUniqueId3,
                                Status = 1
                            };
                            memberContext.ContributionQuotOrg.Add(newContributeQuotRow);
                            topicList = GetAllTopicList(newContributeRow.ContributeId,
                                GetRelatedTopicofAPost(model.NewsClassId, model.QuoteUniqueId1, model.QuoteUniqueId2, model.QuoteUniqueId3));
                            memberContext.QuotTopic.AddRange(topicList);
                            memberContext.SaveChanges();
                            newArticleTransaction.Commit();
                            transactionResult = true;
                        }
                        catch
                        {
                            transactionResult = false;
                            newArticleTransaction.Rollback();
                        }

                    }
                }
                if (transactionResult)
                {
                    string rootPath = Server.MapPath("~");
                    string imagePath = "\\Content\\img\\upload\\contribution\\";
                    string tempImagePath = "\\Content\\img\\upload\\contribution\\tmp_dir\\";
                    string filePath = Path.GetFullPath(rootPath + imagePath);
                    string tempFilePath = Path.GetFullPath(rootPath + tempImagePath);
                    try
                    {
                        if (System.IO.File.Exists(tempFilePath + model.ImageName) && !string.IsNullOrEmpty(model.ImageName))
                        {
                            System.IO.File.Copy(tempFilePath + model.ImageName, filePath + model.ImageName);
                            DeleteTemperaryDir(@"~/Content/img/upload/contribution/tmp_dir/");
                        }
                        else
                        {
                            if (System.IO.Directory.Exists(tempFilePath))
                                DeleteTemperaryDir(@"~/Content/img/upload/contribution/tmp_dir/");
                        }
                    }
                    catch
                    {
                        return View("Error");
                    }

                    var articleListDefault = PostedController.GetRecentPosts(4);
                    var newPost = from a in articleListDefault
                                  where a.ContributeId == newContributionID
                                  select a;

                    return View("CompletePostArticle", newPost);
                }
            }
            else
            {
                return View("Error");
            }
            return View("Error");
        }