Пример #1
0
        public IHttpActionResult GetTravelPlan(int id)
        {
            TravelPlan travelPlan = db.TravelPlans.Find(id);

            if (travelPlan == null)
            {
                return(NotFound());
            }

            return(Ok(travelPlan));
        }
Пример #2
0
        public HttpResponseMessage GetMemberPlansTest(TravelPlan travelPlan)
        {
            Countries country = new Countries();

            var countries = db.Countries.Select(c => new
            {
                c.id,
                c.country,
                city = c.Districts.Where(d => d.Cid == c.id).Select(d => d.city)
            });

            var allPlans = db.TravelPlans.Select(x => new
            {
                x.id,
                x.MemberId,
                x.points,
                Cpicture = x.Cpicture,
                x.MyMember.manpic,
                x.MyMember.name,
                x.country,
                x.city,
                x.CreateOn,

                tags = new
                {
                    x.Act,
                    x.Culture,
                    x.Food,
                    x.Secret,
                    x.Shopping,
                    x.Religion
                },

                rating = db.Ratings.Count(y => y.TravelId == x.id),
                star   = db.Ratings.Where(z => z.TravelId == x.id).Select(z => z.star).Average()
                         //rating = db.Ratings.Where(y => y.TravelId == x.id).Select(y => new
                         //{
                         //    y.rating,
                         //    y.star

                         //})
            }).ToList();



            return(Request.CreateResponse(HttpStatusCode.OK, new { success = true, allPlans, countries }));
        }
Пример #3
0
        public IHttpActionResult DeleteTravelPlan(int id)
        {
            string      token       = Request.Headers.Authorization.Parameter;
            JwtAuthUtil jwtAuthUtil = new JwtAuthUtil();
            int         Mid         = Convert.ToInt32(jwtAuthUtil.GetId(token));

            TravelPlan travelPlan = db.TravelPlans.Find(id);

            if (travelPlan == null)
            {
                return(NotFound());
            }

            db.TravelPlans.Remove(travelPlan);
            db.SaveChanges();

            return(Ok(new { success = true, message = "成功刪除旅行計畫" }));
        }
Пример #4
0
        public HttpResponseMessage PostTravelPlan(TravelPlan travelPlan)
        {
            string      token       = Request.Headers.Authorization.Parameter;
            JwtAuthUtil jwtAuthUtil = new JwtAuthUtil();
            int         Mid         = Convert.ToInt32(jwtAuthUtil.GetId(token));

            //var seller = db.Members.Find(Mid);

            //if (seller.Permission != "02")
            //{
            //    return Request.CreateResponse(HttpStatusCode.BadRequest, new { success = false, message = "非規劃師,無權限" });
            //}


            travelPlan.CreateOn = DateTime.Now; //only year/mth/day
            travelPlan.MemberId = Mid;

            db.TravelPlans.Add(travelPlan);
            db.SaveChanges();

            var result = db.TravelPlans.Where(x => x.id == travelPlan.id).Select(x => new
            {
                x.id,
                x.MemberId,
                x.points,
                x.Cpicture,
                x.TPBGImg,
                x.TPExperience,
                x.TravelPlanIntro,
                x.CreateOn,
                x.country,
                x.city,
                x.Act,
                x.Culture,
                x.Food,
                x.Secret,
                x.Shopping,
                x.Religion
            });

            //var result1 = JsonConvert.SerializeObject(result);
            //traveltype = x.TravelType.ToString(),
            return(Request.CreateResponse(HttpStatusCode.OK, new { success = true, message = "旅行計畫建立成功", result }));
        }
Пример #5
0
        public HttpResponseMessage GetPlanInner(int id)
        {
            TravelPlan travelPlan = db.TravelPlans.Find(id);


            var result = db.TravelPlans.Where(x => x.id == id).Select(x => new
            {
                x.id,
                x.TravelPlanIntro,
                x.TPExperience,
                x.TPBGImg,
                x.Cpicture,
                x.points,
                x.country,
                x.city,
                x.Act,
                x.Culture,
                x.Food,
                x.Shopping,
                x.Secret,
                x.Religion,
                x.MyMember.MemberIntro,
                x.MyMember.name,
                x.MyMember.PlannerSocial1,
                x.MyMember.PlannerSocial2,
                x.MyMember.manpic,

                //rating = db.Ratings.Count(y => y.TravelId == x.id),
                //star = db.Ratings.Where(z => z.TravelId == x.id).Select(z => z.star).Average(),
                //username = db.Orders.Where(a=>a.TravelPlan_id == x.id).Select(a=>a.MyMember.name),
                //userpic = db.Orders.Where(b=>b.TravelPlan_id == x.id).Select(b=>b.MyMember.manpic),

                rating = db.Ratings.Where(y => y.TravelId == x.id).Select(y => new
                {
                    y.rating,
                    y.star,
                    buyerName = db.Orders.Where(z => z.TravelPlan_id == x.id).Select(z => z.MyMember.name).FirstOrDefault(),
                    buyerPic  = db.Orders.Where(a => a.TravelPlan_id == x.id).Select(a => a.MyMember.manpic).FirstOrDefault(),
                    y.RatingContent
                })
            });

            return(Request.CreateResponse(HttpStatusCode.OK, new { success = true, result }));
        }
Пример #6
0
        public HttpResponseMessage PatchTravelPlan(int id, TravelPlan travelPlan)
        {
            string      token       = Request.Headers.Authorization.Parameter;
            JwtAuthUtil jwtAuthUtil = new JwtAuthUtil();
            int         Mid         = Convert.ToInt32(jwtAuthUtil.GetId(token));

            var planChanges = db.TravelPlans.Find(id);

            //TravelPlan travelPlan = db.TravelPlans.Find(id);
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            //if (id != travelPlan.id)
            //{
            //    return Request.CreateResponse(HttpStatusCode.NotFound);
            //}

            //travelPlan.MemberId = Mid;


            planChanges.TravelPlanIntro = travelPlan.TravelPlanIntro;
            planChanges.TPExperience    = travelPlan.TPExperience;
            planChanges.points          = travelPlan.points;
            planChanges.Act             = travelPlan.Act;
            planChanges.Culture         = travelPlan.Culture;
            planChanges.Food            = travelPlan.Food;
            planChanges.Secret          = travelPlan.Secret;
            planChanges.Shopping        = travelPlan.Shopping;
            planChanges.country         = travelPlan.country;
            planChanges.city            = travelPlan.city;


            //db.TravelPlans.Attach(travelPlan);
            //db.Entry(travelPlan).State = EntityState.Modified;
            db.SaveChanges();

            var result = db.TravelPlans.Where(x => x.id == id).Select(x => new
            {
                x.id,
                x.MemberId,
                x.points,
                x.MyMember.name,
                x.TravelPlanIntro,
                x.TPExperience,
                x.country,
                x.city,
                x.Act,
                x.Culture,
                x.Food,
                x.Secret,
                x.Shopping,
                x.Religion

                //tags = db.TravelPlans.Where(z => z.id == travelPlan.id).Select(z => new
                //{
                //    z.Act,
                //    z.Secret,
                //    z.Culture,
                //    z.Food,
                //    z.Shopping,
                //    z.Religion
                //})
            });



            return(Request.CreateResponse(HttpStatusCode.OK, new { success = true, message = "旅行計畫修改成功" }));
        }
Пример #7
0
        public HttpResponseMessage PostOrder(Order order)
        {
            string      token       = Request.Headers.Authorization.Parameter;
            JwtAuthUtil jwtAuthUtil = new JwtAuthUtil();
            int         Mid         = Convert.ToInt32(jwtAuthUtil.GetId(token));


            if (order.TravelPlan_id == 0)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new { success = false, message = "旅行計畫不得為空值" }));
            }



            var        member = db.Members.Find(Mid);
            TravelPlan travel = new TravelPlan();

            order.MemberId = Mid;
            order.CreateOn = DateTime.Now;
            order.Status   = 1;



            var result1 = String.Join("", order.DepartureTime1); // why doesn't it split?

            var planner = db.TravelPlans.Find(order.TravelPlan_id);

            order.PlannerId = planner.MemberId;

            if (Mid == order.PlannerId)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest,
                                              new { success = false, message = "自己的計劃不能自己買RRRRRRRRR" }));
            }


            var currentPoints = member.points - planner.points;

            order.PointsLeft = currentPoints;
            member.points    = currentPoints;



            db.Orders.Add(order);
            db.Entry(member).State = EntityState.Modified;

            db.SaveChanges();

            var result = db.Orders.Where(x => x.id == order.id).Select(x => new
            {
                x.id,
                x.MemberId,
                x.MyMember.name,
                x.MyMember.Tel,
                x.MyMember.Email,
                x.DepartureTime1,
                x.DepartureTime2,
                x.Budget,
                x.Adult,
                x.Children,
                x.country,
                x.city,
                x.Remark,
                x.TravelPlan_id,
                x.PlannerId,
                x.Status,
                x.PointsLeft,
                x.Act,
                x.Culture,
                x.Food,
                x.Shopping,
                x.Secret,
                x.Religion
            });

            return(Request.CreateResponse(HttpStatusCode.OK, new { success = true, message = "旅行計畫建立成功", result }));
        }