public IHttpActionResult Getdeductione()
        {
            string Token  = Request.Headers.Authorization.Parameter;
            int    id     = JwtAuthUtil.GetId(Token);
            var    groups = db.Records.Where(x => x.Student.TeacherId == id).GroupBy(x => x.StudentId);

            var record = groups.Select(x => new
            {
                StudentId     = x.Key,
                StudentNumber = x.FirstOrDefault(y => y.StudentId == x.Key).Student.Id,
                Name          = x.FirstOrDefault(y => y.StudentId == x.Key).Student.Name,
                Deduction     = x.Count(y => y.Attendance == AttendanceType.事假) / 20 * -1 + x.Count(y => y.Attendance == AttendanceType.病假) / 50 * -1 + x.Count(y => y.Attendance == AttendanceType.曠課) / 2 * -1 + x.Count(y => y.Attendance == AttendanceType.遲到) / 3 * -1,
                事假次數          = x.Count(y => y.Attendance == AttendanceType.事假),
                事假扣分          = x.Count(y => y.Attendance == AttendanceType.事假) / 20 * -1,
                病假次數          = x.Count(y => y.Attendance == AttendanceType.病假),
                病假扣分          = x.Count(y => y.Attendance == AttendanceType.病假) / 50 * -1,
                喪假次數          = x.Count(y => y.Attendance == AttendanceType.喪假),
                喪假扣分          = x.Count(y => y.Attendance == AttendanceType.喪假) * 0,
                曠課次數          = x.Count(y => y.Attendance == AttendanceType.曠課),
                曠課扣分          = x.Count(y => y.Attendance == AttendanceType.曠課) / 2 * -1,
                遲到次數          = x.Count(y => y.Attendance == AttendanceType.遲到),
                遲到扣分          = x.Count(y => y.Attendance == AttendanceType.遲到) / 3 * -1,
                Guardian      = x.FirstOrDefault(y => y.StudentId == x.Key).Student.Guardian,
                PhoneNunber   = x.FirstOrDefault(y => y.StudentId == x.Key).Student.PhoneNumber,
                Address       = x.FirstOrDefault(y => y.StudentId == x.Key).Student.Address
            }).OrderBy(x => x.Deduction).ThenBy(x => x.StudentId).ToList();

            return(Ok(new
            {
                code = 1,
                data = record
            }));
        }
        public IHttpActionResult PostRecord(ViewRecord viewRecord)
        {
            int    id     = JwtAuthUtil.GetId(Request.Headers.Authorization.Parameter);
            int    week   = Utility.GetWeek();
            Record record = new Record();

            foreach (var infoitem in viewRecord.StudentInfo)
            {
                record.Subject           = viewRecord.Subject;
                record.ClassId           = viewRecord.ClassId;
                record.LessonOrder       = viewRecord.LessonOrder;
                record.RollCallTime      = DateTime.Now;
                record.LessonDate        = DateTime.Today;
                record.RollCallTeacherId = id;
                record.Week       = (WeekType)week;
                record.StudentId  = infoitem.StudentId;
                record.Attendance = (AttendanceType)infoitem.Attendance;
                db.Records.Add(record);
                db.SaveChanges();
            }
            //return CreatedAtRoute("DefaultApi", new { id = record.Id }, record);
            return(Ok(new
            {
                code = 1,
                message = "點名成功"
            }));
        }
示例#3
0
        public IHttpActionResult GetTimetable()
        {
            string Token = Request.Headers.Authorization.Parameter;
            int    tid   = JwtAuthUtil.GetId(Token);
            int    Week  = Utility.GetWeek();

            if (Week == 0)
            {
                return(Ok(new
                {
                    code = 5588,
                    message = "假日無課表"
                }));
            }
            var result = db.Timetables
                         .Where(x => x.TeacherId == tid && (int)x.Week == Week).OrderBy(x => x.LessonOrder)
                         .Select(x => new
            {
                x.Subject,
                LessonOrder = x.LessonOrder,
                x.ClassId,
                x.Class.ClassName
            });

            return(Ok(new
            {
                code = 1,
                data = result
            }));
        }
示例#4
0
        public IHttpActionResult BrandGetCart(int cartId)
        {
            string      token       = Request.Headers.Authorization.Parameter;
            JwtAuthUtil jwtAuthUtil = new JwtAuthUtil();
            int         id          = Convert.ToInt32(jwtAuthUtil.GetId(token));


            var carts = db.Carts.Where(cart => cart.BrandId == id)
                        .Select(cart => new
            {
                cart.Id,
                cart.CustomerId,
                cart.BrandId,
                cart.BrandName,
                ProductList = new
                {
                    cart.ProductListId,
                    cart.ProductName,
                    cart.ProductUnit,
                    cart.Amount
                }
            });

            return(Ok(new
            {
                result = true,
                carts
            }));
        }
示例#5
0
        public IHttpActionResult GetContactrecordPrint([FromUri] ViewSearch viewSearch)
        {
            string Token  = Request.Headers.Authorization.Parameter;
            int    id     = JwtAuthUtil.GetId(Token);
            var    result = db.Contactrecords.AsQueryable();

            if (viewSearch.StudentId.HasValue)
            {
                result = result.Where(x => x.StudentId == viewSearch.StudentId);
            }
            if (viewSearch.StartDate.HasValue && viewSearch.EndDate.HasValue)
            {
                viewSearch.EndDate = viewSearch.EndDate.Value.AddDays(1);
                result             = result.Where(x => x.ContactDateTime >= viewSearch.StartDate && x.ContactDateTime <= viewSearch.EndDate);
            }
            var students = db.Students.AsQueryable();
            var data     = result.Select(x => new
            {
                Id              = x.Id,
                Time            = x.ContactDateTime,
                StudentName     = students.FirstOrDefault(y => y.Id == x.StudentId).Name,
                ContactGuardian = x.ContactGuardian,
                Teacher         = x.Teacher.Name,
                Method          = x.Method,
                Reason          = x.Reason,
                Results         = x.Results
            });

            return(Ok(new
            {
                code = 1,
                data = data
            }));
        }
示例#6
0
        public HttpResponseMessage GetMemberPlans()
        {
            string      token       = Request.Headers.Authorization.Parameter;
            JwtAuthUtil jwtAuthUtil = new JwtAuthUtil();
            int         Mid         = Convert.ToInt32(jwtAuthUtil.GetId(token));

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

            var result = db.TravelPlans.Where(x => x.MemberId == Mid).Select(x => new
            {
                id       = x.id,
                MemberId = x.MyMember.id,
                x.points,
                x.Cpicture,
                x.TravelPlanIntro,
                x.TPExperience,
                x.CreateOn,
                x.country,
                x.city,

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

            //string newResult = JsonConvert.SerializeObject(result);
            // HttpContext.Current.Response.Headers.Add("Content-Type", "application/json; charset=utf-8");
            return(Request.CreateResponse(HttpStatusCode.OK, new { success = true, result }));
        }
示例#7
0
        public IHttpActionResult GetBrandOrder()
        {
            string       token       = Request.Headers.Authorization.Parameter;
            JwtAuthUtil  jwtAuthUtil = new JwtAuthUtil();
            int          id          = Convert.ToInt32(jwtAuthUtil.GetId(token));
            List <Order> orders      = db.Orders.Where(o => o.BrandId == id && o.InitDate > DateTime.Today).ToList();
            var          today       = orders.Select(x => new
            {
                x.Id,
                x.CustomerId,
                status = x.OrderStatus.ToString(),
                x.OrderNumber,
                brandName = x.Brand.BrandName,
                x.LinepayVer,
                Total = x.OrderDetails.Sum(o => o.Amount),
                Site  = x.Site.ToString(),
                x.OrderDetails
            }).ToList();

            return(Ok(new
            {
                success = true,
                today,
            }));
        }
示例#8
0
        public HttpResponseMessage DeleteOrder(int id)
        {
            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 = "使用者權限非規劃師,無刪除權限" }));
            }
            Order order = db.Orders.Find(id);

            if (order == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, new { success = false, message = "查無此訂單" }));
            }

            db.Orders.Remove(order);
            db.SaveChanges();

            return(Request.CreateResponse(HttpStatusCode.OK, new{ success = true, message = "成功刪除訂單" }));
        }
示例#9
0
        public HttpResponseMessage PostBackgroundImage()
        {
            string      token       = Request.Headers.Authorization.Parameter;
            JwtAuthUtil jwtAuthUtil = new JwtAuthUtil();
            int         Mid         = Convert.ToInt32(jwtAuthUtil.GetId(token));
            Member      member      = db.Members.Find(Mid);

            try
            {
                var postedFile = HttpContext.Current.Request.Files.Count > 0
                    ? HttpContext.Current.Request.Files[0]
                    : null;
                if (postedFile != null && postedFile.ContentLength > 0)
                {
                    //string extension = postedFile.FileName.Split('.')[postedFile.FileName.Split('.').Length - 1];
                    //int MaxContentLength = 1024 * 1024 * 1; //Size = 1MB
                    string fileName = Utility.UploadImage(postedFile);
                    //IList<string> AllowedFileExtensions = new List<string> {".jpg", ".png", ".svg"};

                    //if (!AllowedFileExtensions.Contains(extension))
                    //{
                    //    return Request.CreateResponse(HttpStatusCode.BadRequest, new
                    //    {
                    //        success = false,
                    //        message = "請上傳圖片正確格式,可接受格式為 .jpg, .png, .svg"
                    //    });
                    //}

                    UriBuilder uriBuilder = new UriBuilder(HttpContext.Current.Request.Url)
                    {
                        Path = $"/Upload/BGimg/{fileName}"
                    };
                    //Userimage myfolder name where i want to save my image
                    Uri imgUploadUrl = uriBuilder.Uri;
                    member.BGImg = imgUploadUrl.ToString();

                    db.Entry(member).State = EntityState.Modified;
                    db.SaveChanges();

                    return(Request.CreateResponse(HttpStatusCode.OK, new
                    {
                        success = true,
                        message = "已上傳個人圖片",
                        imgUploadUrl
                    }));
                }

                return(Request.CreateResponse(HttpStatusCode.NotFound, new
                {
                    success = false,
                    message = "無圖片,請選擇圖片上傳"
                }));
            }
            catch
            {
                throw;
            }

            return(Request.CreateResponse());
        }
示例#10
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 }));
        }
示例#11
0
        public IHttpActionResult GetStudentsDeduction()
        {
            int id     = JwtAuthUtil.GetId(Request.Headers.Authorization.Parameter);
            var groups = db.Records.Where(x => x.StudentId == id).GroupBy(x => x.StudentId);
            var record = groups.Select(x => new
            {
                事假次數      = x.Count(y => y.Attendance == AttendanceType.事假),
                事假扣分      = x.Count(y => y.Attendance == AttendanceType.事假) / 20 * -1,
                病假次數      = x.Count(y => y.Attendance == AttendanceType.病假),
                病假扣分      = x.Count(y => y.Attendance == AttendanceType.病假) / 50 * -1,
                喪假次數      = x.Count(y => y.Attendance == AttendanceType.喪假),
                喪假扣分      = x.Count(y => y.Attendance == AttendanceType.喪假) * 0,
                曠課次數      = x.Count(y => y.Attendance == AttendanceType.曠課),
                曠課扣分      = x.Count(y => y.Attendance == AttendanceType.曠課) / 2 * -1,
                遲到次數      = x.Count(y => y.Attendance == AttendanceType.遲到),
                遲到扣分      = x.Count(y => y.Attendance == AttendanceType.遲到) / 3 * -1,
                Deduction = x.Count(y => y.Attendance == AttendanceType.事假) / 20 * -1 + x.Count(y => y.Attendance == AttendanceType.病假) / 50 * -1 + x.Count(y => y.Attendance == AttendanceType.曠課) / 2 * -1 + x.Count(y => y.Attendance == AttendanceType.遲到) / 3 * -1,
            });

            return(Ok(new
            {
                code = 1,
                data = record.ToList()
            }));
        }
示例#12
0
        public IHttpActionResult PostNotice(ViewNoitce viewNoitce)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            string      token       = Request.Headers.Authorization.Parameter;
            JwtAuthUtil jwtAuthUtil = new JwtAuthUtil();
            int         id          = Convert.ToInt32(jwtAuthUtil.GetId(token));
            var         brand       = db.Brands.FirstOrDefault(b => b.Id == id);
            var         orders      = db.Orders.FirstOrDefault(o => o.Id == viewNoitce.OrderId);

            Notice notice = new Notice();

            notice.CustomerId  = orders.CustomerId;
            notice.OrderId     = viewNoitce.OrderId;
            notice.OrderStatus = viewNoitce.OrderStatus;
            notice.Remarks     = viewNoitce.Remarks;
            notice.IsRead      = 0;
            db.Notices.Add(notice);
            db.SaveChanges();
            return(Ok(new
            {
                result = true,
                message = "通知訊息已新增成功!"
            }));
        }
        public IHttpActionResult PostMyFollow(MyFollow myFollow)
        {
            //顧客資料
            string      token       = Request.Headers.Authorization.Parameter;
            JwtAuthUtil jwtAuthUtil = new JwtAuthUtil();
            int         id          = Convert.ToInt32(jwtAuthUtil.GetId(token));

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var checkMyfollow = db.MyFollows.FirstOrDefault(m => m.BrandId == myFollow.BrandId && m.CustomerId == id);

            if (checkMyfollow != null)
            {
                return(Ok(new
                {
                    result = false,
                    message = "此餐車已經加入追蹤"
                }));
            }

            myFollow.CustomerId = id;
            myFollow.BrandName  = db.Brands.FirstOrDefault(b => b.Id == myFollow.BrandId).BrandName;//換成show brandid
            db.MyFollows.Add(myFollow);
            db.SaveChanges();
            return(Ok(new
            {
                result = true,
                message = "已加入追蹤",
            }));
        }
示例#14
0
        public IHttpActionResult GetSellerSingleOrder(int id)
        {
            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(BadRequest());
            }

            var result = db.Orders.Where(x => x.PlannerId == Mid && x.id == id).Select(x => new
            {
                x.id,
                x.MemberId,
                x.MyMember.name,
                x.MyMember.Tel,
                x.MyMember.manpic,
                x.DepartureTime1,
                x.DepartureTime2,
                x.Budget,
                x.Adult,
                x.Children,
                x.country,
                x.city,
                x.TravelPlan_id,
                x.CreateOn,
                x.Status,
            }).ToList();

            return(Ok(new { success = true, result }));
        }
示例#15
0
        public IHttpActionResult GetStudentsRecords([FromUri] ViewSearch viewSearch)
        {
            int id     = JwtAuthUtil.GetId(Request.Headers.Authorization.Parameter);
            var result = db.Records.Where(x => x.StudentId == id).AsQueryable();

            if (viewSearch.StartDate.HasValue && viewSearch.EndDate.HasValue)
            {
                //因為LessonDate設定為Datetime.today,所以不須再加一天,如下行處理
                //Search.EndDate = viewSearch.EndDate.Value.AddDays(1);
                result = result.Where(x => x.LessonDate >= viewSearch.StartDate && x.LessonDate <= viewSearch.EndDate);
            }
            if (viewSearch.Attendance.HasValue)
            {
                result = result.Where(x => x.Attendance == viewSearch.Attendance);
            }
            var teacher = db.Teachers.AsQueryable();
            var data    = result.Select(x => new
            {
                x.LessonDate,
                x.LessonOrder,
                x.Subject,
                Teacher    = teacher.FirstOrDefault(y => y.Id == x.RollCallTeacherId).Name,
                Attendance = x.Attendance.ToString()
            }).OrderBy(x => x.LessonDate).ToList();

            return(Ok(new
            {
                code = 1,
                data = data
            }));
        }
示例#16
0
        public HttpResponseMessage PostWishBoard(WishBoard wishBoard)
        {
            string      token       = Request.Headers.Authorization.Parameter;
            JwtAuthUtil jwtAuthUtil = new JwtAuthUtil();
            int         Mid         = Convert.ToInt32(jwtAuthUtil.GetId(token));

            if (!ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            wishBoard.MemberId = Mid;
            wishBoard.CreateOn = DateTime.Now;

            db.WishBoards.Add(wishBoard);
            db.SaveChanges();

            var result = db.WishBoards.Where(x => x.MemberId == Mid).Select(x => new
            {
                x.id,
                MemberId = x.MyMember.id,
                x.MyMember.manpic,
                x.MyMember.name,
                x.Comment1,
                x.Comment2,
                x.CreateOn
            });

            return(Request.CreateResponse(HttpStatusCode.OK, new { success = true, message = "留言成功", result }));
        }
        public IHttpActionResult GetMyFollow()
        {
            string      token       = Request.Headers.Authorization.Parameter;
            JwtAuthUtil jwtAuthUtil = new JwtAuthUtil();
            int         id          = Convert.ToInt32(jwtAuthUtil.GetId(token));

            SqlConnection Conn = new SqlConnection();

            Conn.ConnectionString = ConfigurationManager.ConnectionStrings["Model1"].ConnectionString;
            DataTable dt = new DataTable();

            SqlCommand cmd = new SqlCommand(@"select f.Id,f.BrandId,f.BrandName,left(convert(varchar,o.SDateTime,108),5) SDateTime,
                           left(convert(varchar,o.EDateTimeDate,108),5) EDateTimeDate,o.Location
                           from MyFollows f inner join OpenTimes o on f.BrandId = o.BrandId
                           where f.CustomerId=@id and o.OpenDate = convert(varchar,getdate(),111)", Conn);

            cmd.Parameters.AddWithValue("@id", id);
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);

            adapter.Fill(dt);


            return(Ok(new
            {
                result = true,
                dt
            }));
        }
示例#18
0
        //[Route("account")]
        public HttpResponseMessage PatchMember(PatchMember patchMember)
        {
            string      token       = Request.Headers.Authorization.Parameter;
            JwtAuthUtil jwtAuthUtil = new JwtAuthUtil();
            int         Mid         = Convert.ToInt32(jwtAuthUtil.GetId(token));


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


            if (member.Permission == "01")
            {
                patchMember.Password = Utility.GenerateHashWithSalt(patchMember.Password, member.PasswordSalt);
                patchMember.Patch(member);

                db.SaveChanges();

                var result1 = db.Members.Where(x => x.id == Mid).Select(x => new
                {
                    x.id,
                    x.name,
                    x.Tel,
                    x.MemberIntro,
                    x.PlannerSocial1,
                    x.PlannerSocial2,
                });

                //string result = JsonConvert.DeserializeObject<PatchMember>(result1).ToString();

                return(Request.CreateResponse(HttpStatusCode.OK, new { success = true, message = "成功修改", result1 }));
            }

            if (member.Permission == "02")
            {
                patchMember.Password = Utility.GenerateHashWithSalt(patchMember.Password, member.PasswordSalt);
                patchMember.Patch(member);

                db.SaveChanges();

                var result2 = db.Members.Where(x => x.id == Mid).Select(x => new
                {
                    x.id,
                    x.name,
                    x.Tel,
                    x.MemberIntro,
                    x.PlannerSocial1,
                    x.PlannerSocial2,
                    x.PlannerName,
                    x.PlannerIntro,
                    x.PlannerSocial3,
                    x.PlannerSocial4,
                });

                return(Request.CreateResponse(HttpStatusCode.OK, new { success = true, message = "規劃師成功修改", result2 }));
            }

            return(Request.CreateResponse(HttpStatusCode.NoContent, new { message = "沒東西R" }));
        }
示例#19
0
        public HttpResponseMessage PostUploadImage()
        {
            string      token       = Request.Headers.Authorization.Parameter;
            JwtAuthUtil jwtAuthUtil = new JwtAuthUtil();
            int         id          = Convert.ToInt32(jwtAuthUtil.GetId(token));
            Brand       brand       = db.Brands.Find(id);

            try
            {
                var file = HttpContext.Current.Request.Files.Count > 0
                    ? HttpContext.Current.Request.Files[0]
                    : null;

                if (file != null && file.ContentLength > 0)
                {
                    //新的檔案名稱
                    string fileName = Utility.UploadBrandImage(file);


                    //產生圖片連結
                    UriBuilder uriBuilder = new UriBuilder(HttpContext.Current.Request.Url)
                    {
                        Path = $"/Upload/brand/info/{fileName}"
                    };

                    Uri imageUrl = uriBuilder.Uri;
                    brand.LogoPhoto = imageUrl.ToString();
                    brand.CarImage  = imageUrl.ToString();
                    brand.QrCode    = imageUrl.ToString();

                    db.Entry(brand).State = EntityState.Modified;
                    db.SaveChanges();


                    return(Request.CreateResponse(HttpStatusCode.OK, new
                    {
                        success = true,
                        message = "圖片上傳成功",
                        imageUrl
                    }));
                }


                return(Request.CreateResponse(HttpStatusCode.OK, new
                {
                    result = false,
                    message = "請選擇上傳圖片!"
                }));
            }
            catch
            {
                throw;
            }
        }
示例#20
0
        //[Route("account")]

        public HttpResponseMessage PatchMember(Member member)
        {
            string      token       = Request.Headers.Authorization.Parameter;
            JwtAuthUtil jwtAuthUtil = new JwtAuthUtil();
            int         Mid         = Convert.ToInt32(jwtAuthUtil.GetId(token));

            if (!ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

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

            change.name           = member.name;
            change.PasswordSalt   = Utility.CreateSalt();
            change.Password       = Utility.GenerateHashWithSalt(member.Password, change.PasswordSalt);
            change.Tel            = member.Tel;
            change.PlannerSocial1 = member.PlannerSocial1;
            change.PlannerSocial2 = member.PlannerSocial2;

            //db.Entry(member).State = EntityState.Modified;

            try
            {
                db.SaveChanges();

                var result = db.Members.Where(x => x.id == Mid).Select(x => new
                {
                    x.id,
                    x.Email,
                    x.name,
                    x.Tel,
                    x.MemberIntro,
                    x.PlannerSocial1,
                    x.PlannerSocial2,
                });

                return(Request.CreateResponse(HttpStatusCode.OK, new { success = true, message = "成功修改", result }));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MemberExists(Mid))
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }
                else
                {
                    throw;
                }
            }

            return(Request.CreateResponse(HttpStatusCode.NoContent));
        }
示例#21
0
        public IHttpActionResult GetMemberSingleOrder(int id)
        {
            string      token       = Request.Headers.Authorization.Parameter;
            JwtAuthUtil jwtAuthUtil = new JwtAuthUtil();
            int         Mid         = Convert.ToInt32(jwtAuthUtil.GetId(token));


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

                PlannerName = db.TravelPlans.Where(y => y.id == x.TravelPlan_id).Select(y => new
                {
                    y.MyMember.name
                })

                              //PlanPic = x.MyMember.TravelPlans.Where(z => z.id == x.TravelPlan_id).Select(z => new
                              //{
                              //    z.Cpicture
                              //}),

                              // Plan = db.TravelPlans.Where(y=>y.id == x.TravelPlan_id).Select(y=>new{
                              //    y.Cpicture
                              //})
            }).ToList();

            return(Ok(new { success = true, result }));
        }
示例#22
0
        public HttpResponseMessage GetPointsHistory()
        {
            string      token       = Request.Headers.Authorization.Parameter;
            JwtAuthUtil jwtAuthUtil = new JwtAuthUtil();
            int         Mid         = Convert.ToInt32(jwtAuthUtil.GetId(token));


            var result = db.PointsHistories.Where(x => x.MemberId == Mid).Select(x => new
            {
                x.Product,
                x.CreateOn
            });

            return(Request.CreateResponse(HttpStatusCode.OK, new { success = true, result }));
        }
        public IHttpActionResult GetStudents()
        {
            string Token  = Request.Headers.Authorization.Parameter;
            int    id     = JwtAuthUtil.GetId(Token);
            var    result = db.Students.Where(x => x.TeacherId == id).Select(x => new
            {
                x.Id,
                x.Name
            }).OrderBy(x => x.Id);

            return(Ok(new
            {
                code = 1,
                data = result
            }));
        }
示例#24
0
        public HttpResponseMessage GetAuthMemberPlans()
        {
            string      token       = Request.Headers.Authorization.Parameter;
            JwtAuthUtil jwtAuthUtil = new JwtAuthUtil();
            int         Mid         = Convert.ToInt32(jwtAuthUtil.GetId(token));

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

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

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

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

                rating = db.Ratings.Where(y => y.TravelId == x.id).Select(y => new
                {
                    y.star,
                    y.rating
                })
            });

            return(Request.CreateResponse(HttpStatusCode.OK, new { success = true, allPlans, countries }));
        }
        public IHttpActionResult GetRecords()
        {
            DateTime Sdate       = DateTime.Today;
            DateTime Edate       = DateTime.Today.AddDays(1);
            string   Token       = Request.Headers.Authorization.Parameter;
            int      id          = JwtAuthUtil.GetId(Token);
            var      todaydatas  = db.Records.Where(x => x.LessonDate >= Sdate && x.LessonDate <= Edate && x.Student.TeacherId == id);
            var      gropBydatas = todaydatas.GroupBy(x => x.LessonOrder);
            var      records     = gropBydatas.Select(x => new
            {
                result = new
                {
                    LessonOrder = x.Key,
                    遲到          = x.Where(y => y.Attendance == AttendanceType.遲到).Select(y => new
                    {
                        y.Student.Name
                    }),
                    曠課 = x.Where(y => y.Attendance == AttendanceType.曠課).Select(y => new
                    {
                        y.Student.Name
                    }),
                    病假 = x.Where(y => y.Attendance == AttendanceType.病假).Select(y => new
                    {
                        y.Student.Name
                    }),
                    事假 = x.Where(y => y.Attendance == AttendanceType.事假).Select(y => new
                    {
                        y.Student.Name
                    }),
                    喪假 = x.Where(y => y.Attendance == AttendanceType.喪假).Select(y => new
                    {
                        y.Student.Name
                    }),
                    出席 = x.Where(y => y.Attendance == AttendanceType.出席).Select(y => new
                    {
                        y.Student.Name
                    })
                }
            });

            return(Ok(new
            {
                code = 1,
                data = records
            }));
        }
示例#26
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 = "成功刪除旅行計畫" }));
        }
示例#27
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 }));
        }
示例#28
0
        public HttpResponseMessage PostUploadImage()
        {
            string      token       = Request.Headers.Authorization.Parameter;
            JwtAuthUtil jwtAuthUtil = new JwtAuthUtil();
            int         id          = Convert.ToInt32(jwtAuthUtil.GetId(token));
            Customer    customer    = db.Customers.Find(id);

            var file = HttpContext.Current.Request.Files.Count > 0
                    ? HttpContext.Current.Request.Files[0] : null;

            if (file != null && file.ContentLength > 0)
            {
                //新的檔案名稱
                string fileName = Utility.UploadImage(file);


                //產生圖片連結
                UriBuilder uriBuilder = new UriBuilder(HttpContext.Current.Request.Url)
                {
                    Path = $"/Upload/customer/{fileName}"
                };

                Uri imageUrl = uriBuilder.Uri;
                customer.CusPhoto = imageUrl.ToString();

                db.Entry(customer).State = EntityState.Modified;
                db.SaveChanges();


                return(Request.CreateResponse(HttpStatusCode.OK, new
                {
                    success = true,
                    message = "已上傳個人圖片",
                    imageUrl
                }));
            }


            return(Request.CreateResponse(HttpStatusCode.OK, new
            {
                result = false,
                message = "請選擇上傳圖片!"
            }));
        }
示例#29
0
        public IHttpActionResult PostContactrecord(Contactrecord contactrecord)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            string Token = Request.Headers.Authorization.Parameter;
            int    Id    = JwtAuthUtil.GetId(Token);

            contactrecord.TeacherId = Id;
            db.Contactrecords.Add(contactrecord);
            db.SaveChanges();

            return(Ok(new
            {
                code = 1,
                message = "紀錄完成"
            }));
        }
        public IHttpActionResult PostFeedBack(ViewFeedBack viewFeedBack)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            string      token       = Request.Headers.Authorization.Parameter;
            JwtAuthUtil jwtAuthUtil = new JwtAuthUtil();
            int         id          = Convert.ToInt32(jwtAuthUtil.GetId(token));
            var         orders      = db.Orders.FirstOrDefault(o => o.CustomerId == id && o.OrderStatus == OrderStatus.訂單完成 && o.Id == viewFeedBack.OrderId);

            FeedBack feedBack = new FeedBack();

            if (orders == null)
            {
                return(Ok(new
                {
                    result = false,
                    message = "訂單狀態尚未完成,無法填寫回饋單!"
                }));
            }

            feedBack.CustomerId = id;
            string guid = Guid.NewGuid().ToString("N");

            feedBack.Guid       = guid;
            feedBack.OrderId    = viewFeedBack.OrderId;
            feedBack.Food       = viewFeedBack.Food;
            feedBack.Service    = viewFeedBack.Service;
            feedBack.AllSuggest = viewFeedBack.AllSuggest;
            feedBack.CarSuggest = viewFeedBack.CarSuggest;

            db.FeedBacks.Add(feedBack);
            db.SaveChanges();

            return(Ok(new
            {
                result = true,
                message = "回饋單已填寫完成",
            }));
        }