示例#1
0
        public IActionResult Edit(CPostViewModel post)
        {
            try
            {
                if (post != null)
                {
                    TPost P_被修改 = context.TPosts.FirstOrDefault(n => n.FPostId == post.FPostId);

                    if (P_被修改 != null)
                    {
                        P_被修改.FTitle        = post.FTitle;
                        P_被修改.FDescription  = post.FDescription;
                        P_被修改.FPeople       = post.FPeople;
                        P_被修改.FPostAddress  = post.FPostAddress;
                        P_被修改.FPostCity     = post.FPostCity;
                        P_被修改.FPostDistrict = post.FPostDistrict;
                        P_被修改.FPostTime     = post.FPostTime;
                        P_被修改.FSportName    = post.FSportName;
                        P_被修改.FSystemTime   = DateTime.Now.ToString();
                        P_被修改.FPostCheck    = post.FPostCheck;
                        P_被修改.FLikeCount    = post.FLikeCount.ToString();
                        //TJoinPerson joinPerson = new TJoinPerson(); //參加人
                        //joinPerson.FUserId = post.FUserId;
                        //joinPerson.FPostId = post.FPostId;


                        if (post.image != null)
                        {
                            foreach (var i in post.image)
                            {
                                string PhotoName = Guid.NewGuid().ToString() + ".jpg";
                                using (var photo = new FileStream(iv_host.ContentRootPath + @"/wwwroot/img/" + PhotoName, FileMode.Create))
                                {
                                    i.CopyTo(photo);
                                }
                                TPostPhoto tp = new TPostPhoto();
                                tp.FPostPhoto = "~/img/" + PhotoName;
                                tp.FPostId    = post.FPostId;
                                context.TPostPhotos.Add(tp);
                                context.SaveChanges();
                            }
                        }
                        context.SaveChanges();
                    }
                }
                return(RedirectToAction("Post_Index", "CPost"));
            }
            catch
            {
                return(RedirectToAction("Post_Index", "CPost"));
            }
        }
示例#2
0
 public IActionResult Edit_img(string img)
 {
     try
     {
         TPostPhoto photo = context.TPostPhotos.FirstOrDefault(n => n.FPostPhotoId == int.Parse(img));
         context.TPostPhotos.Remove(photo);
         context.SaveChanges();
         return(RedirectToAction("Edit"));
     }
     catch
     {
         return(RedirectToAction("Post_Index", "CPost"));
     }
 }
示例#3
0
        public IActionResult Post_Create(CPostViewModel cPost, string[] tag)
        {
            try
            {
                for (int i = 0; i < tag.Count(); i++)
                {
                    Tag.Add(tag[i]);
                }
                user = cPost.FUserId;
                //context.Add(cPost);

                TPost new_Post = new TPost
                {
                    FUserId       = cPost.FUserId, //todo
                    FDescription  = cPost.FDescription,
                    FPeople       = cPost.FPeople,
                    FPostCity     = cPost.FPostCity,
                    FPostAddress  = cPost.FPostAddress,
                    FPostDistrict = cPost.FPostDistrict,
                    FPostTime     = cPost.FPostTime,
                    FSportName    = cPost.FSportName,
                    FSystemTime   = DateTime.Now.ToString(),
                    FTitle        = cPost.FTitle,
                };
                context.TPosts.Add(new_Post);
                context.SaveChanges();

                foreach (var i in Tag) //標籤
                {
                    TPostTag postTag = new TPostTag();
                    postTag.FTagId  = int.Parse(i);
                    postTag.FPostId = new_Post.FPostId;
                    context.TPostTags.Add(postTag);
                    context.SaveChanges();
                }

                TJoinPerson joinPerson = new TJoinPerson(); //參加人
                joinPerson.FUserId   = new_Post.FUserId;
                joinPerson.FPostId   = new_Post.FPostId;
                joinPerson.FJoinTime = DateTime.Now.ToString();

                TPostSport postSport = new TPostSport();  //活動種類
                postSport.FPostId    = new_Post.FPostId;
                postSport.FSportName = new_Post.FSportName;


                context.TJoinPeople.Add(joinPerson);
                context.SaveChanges();
                if (cPost.image != null)
                {
                    foreach (var i in cPost.image)
                    {
                        string photoName = Guid.NewGuid().ToString() + ".jpg";
                        using (var photo = new FileStream(iv_host.ContentRootPath + @"/wwwroot/Postimg/" + photoName, FileMode.Create))
                        {
                            i.CopyTo(photo);
                        }
                        TPostPhoto postPhoto = new TPostPhoto();
                        postPhoto.FPostId    = new_Post.FPostId;
                        postPhoto.FPostPhoto = @"/Postimg/" + photoName;
                        context.TPostPhotos.Add(postPhoto);
                        context.SaveChanges();
                    }
                }
                return(RedirectToAction("Post_Index", "CPost"));
            }
            catch
            {
                return(RedirectToAction("Post_Index", "CPost"));
            }
        }