Ejemplo n.º 1
0
        public IHttpActionResult PutMessage(int id, Message message)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != message.id)
            {
                return(BadRequest());
            }

            db.Entry(message).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MessageExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 2
0
        public HttpResponseMessage PostMessage(Message message)
        {
            string      token       = Request.Headers.Authorization.Parameter;
            JwtAuthUtil jwtAuthUtil = new JwtAuthUtil();
            int         Mid         = Convert.ToInt32(jwtAuthUtil.GetId(token));

            if (message.TravelPlanId == 0)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest,
                                              new { success = false, message = "no such plan exists" }));
            }
            TravelPlan travelPlan = new TravelPlan();

            message.CreateOn = DateTime.Now;
            var planner = db.TravelPlans.Find(message.TravelPlanId);

            message.PlannerId = planner.MemberId;
            message.MemberId  = Mid;


            db.Messages.Add(message);
            db.SaveChanges();

            var result = db.Messages.Where(x => x.TravelPlanId == planner.id).Select(x => new
            {
                x.id,
                x.TravelPlanId,
                x.Body,
                x.CreateOn,
                buyer  = message.MemberId,
                seller = message.PlannerId
            });

            return(Request.CreateResponse(HttpStatusCode.OK, new { success = true, message = "訊息傳送成功", result }));
        }
Ejemplo n.º 3
0
        public IHttpActionResult DeleteMessage(int id)
        {
            Message message = db.Messages.Find(id);

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

            db.Messages.Remove(message);
            db.SaveChanges();

            return(Ok(message));
        }
Ejemplo n.º 4
0
        public HttpResponseMessage GetMessage(Message message)
        {
            string      token       = Request.Headers.Authorization.Parameter;
            JwtAuthUtil jwtAuthUtil = new JwtAuthUtil();
            int         Mid         = Convert.ToInt32(jwtAuthUtil.GetId(token));

            var member = db.Members.Find(Mid);

            //if (message.TravelPlanId == 0)
            //{
            //    return Request.CreateResponse(HttpStatusCode.BadRequest,
            //        new {success = false, message = "無此計畫訊息內容"});
            //}

            var plan = db.Messages.Find(Mid);



            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Ejemplo n.º 5
0
        public HttpResponseMessage GetBuyerMessage(Message message)
        {
            string      token       = Request.Headers.Authorization.Parameter;
            JwtAuthUtil jwtAuthUtil = new JwtAuthUtil();
            int         Mid         = Convert.ToInt32(jwtAuthUtil.GetId(token));

            var sellerCheck = db.Messages.Find(Mid);

            message.PlannerId = Mid;

            var result = db.Messages.Where(x => x.PlannerId == Mid).Select(x => new
            {
                x.id,
                x.TravelPlanId,
                x.Body,
                x.CreateOn,
                buyer = x.MemberId
            });

            return(Request.CreateResponse(HttpStatusCode.OK, new { success = true, message = "賣家獲得所有訊息", result }));
        }