예제 #1
0
        public static void Main(string[] args)
        {
            using (var db = new CWContext())
            {
                db.Database.Migrate();

                db.SaveChanges();
            }

            var config = new ConfigurationBuilder()
                         .SetBasePath(Directory.GetCurrentDirectory())
                         .AddJsonFile("appsettings.json", optional: false)
                         .AddJsonFile("hosting.json", optional: true)
                         .AddCommandLine(args)
                         .Build();

            Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup <Startup>();
                webBuilder.UseConfiguration(config);
            })
            .Build()
            .Run();
        }
예제 #2
0
        static async Task Main(string[] args)
        {
            using var db = new CWContext();
            db.Database.Migrate();

            db.SaveChanges();

            //await FillCourses();
            //await FillAreas();
        }
예제 #3
0
        public ActionResult TutorCreateBlog(BlogVM model, HttpPostedFileBase File)
        {
            var myPath = "";

            if (File != null && File.ContentLength > 0)
            {
                string _FileName = Path.GetFileName(File.FileName);
                myPath = _FileName;
                string _Path = Path.Combine(Server.MapPath("~/UploadFiles"), _FileName);
                File.SaveAs(_Path);
                ViewBag.Message = "File Uploaded Successfully!!";
            }
            if (ModelState.IsValid)
            {
                var CurrentUser = db.Users.Where(h => h.UserName == HttpContext.User.Identity.Name).FirstOrDefault();
                if (CurrentUser != null)
                {
                    model.Creator  = CurrentUser.Profile.Name;
                    model.FileName = myPath;
                    Blog newBlog = new Blog();
                    newBlog.Content    = model.Content;
                    newBlog.CreateDate = model.CreateDate;
                    newBlog.FileName   = model.FileName;
                    if (CurrentUser.Role.id == 2)
                    {
                        newBlog.Group = CurrentUser.Group;
                    }
                    else
                    {
                        newBlog.Group = CurrentUser.GroupMember.Group;
                    }
                    newBlog.Title   = model.Title;
                    newBlog.Creator = model.Creator;
                    db.Blogs.Add(newBlog);
                    db.SaveChanges();
                }
            }
            return(RedirectToAction("Index", "TutorBlog"));
        }
예제 #4
0
        public ActionResult CalculatePrice(Ticket t)
        {
            var obj = _context.RouteStops.Include(x => x.City)
                      .Include(x => x.Route).FirstOrDefault(x => x.StopId == t.RouteStopFrom);
            var obj2 = _context.RouteStops.Include(x => x.City)
                       .Include(x => x.Route).FirstOrDefault(x => x.StopId == t.RouteStopTo);

            obj.DistanceToStop  = CalcDist(obj.Route.CityFromNavigation, obj.City);
            obj2.DistanceToStop = CalcDist(obj2.Route.CityFromNavigation, obj2.City);
            var      schedule  = tmpobj as Schedule;
            var      transport = _context.Transports.FirstOrDefault(x => x.TransportId == schedule.TransportId);
            DateTime startTime = CalcTime(schedule, obj);
            DateTime endTime   = CalcTime(schedule, obj2);

            t.ScheduleId = schedule.ScheduleId;
            t.Price      = (decimal)((transport.PricePerKm * (decimal?)(obj2.DistanceToStop - obj.DistanceToStop)));
            if (t.Price > 1000 && t.Price < 10000)
            {
                t.Price /= 10;
            }
            else if (t.Price > 10001)
            {
                t.Price /= 100;
            }
            t.RouteStopFrom = obj.StopId;
            t.RouteStopTo   = obj2.StopId;
            t.StartTime     = startTime;
            t.ArrivalTime   = endTime;
            t.DateAdded     = DateTime.Now;
            t.DateUpdated   = DateTime.Now;
            _context.Add(t);
            _context.SaveChanges();
            var tc = _context.Tickets.ToList().Last();

            return(RedirectToAction("Create", tc));
        }
        public JsonResult SaveChat(string accountId, string chatContent)
        {
            var CurrentName = db.Users.FirstOrDefault(h => h.UserName == HttpContext.User.Identity.Name);

            try
            {
                int      friendAccountId = int.Parse(accountId);
                ChatBox  chatBoxFriend   = db.ChatBoxes.FirstOrDefault(c => c.User.id == friendAccountId);
                ChatBox  myChatBox       = db.ChatBoxes.FirstOrDefault(c => c.User.id == CurrentName.id);
                DateTime current         = DateTime.Now;
                Chat     newChat         = new Chat()
                {
                    SendPersonId    = CurrentName.id,
                    ReceivePersonId = friendAccountId,
                    ChatBox         = chatBoxFriend,
                    Content         = chatContent,
                    IsSent          = true,
                    CreatedDate     = current.Date
                };

                Chat newChat2 = new Chat()
                {
                    SendPersonId    = friendAccountId,
                    ReceivePersonId = CurrentName.id,
                    ChatBox         = myChatBox,
                    Content         = chatContent,
                    CreatedDate     = current.Date
                };
                db.Chats.Add(newChat);
                db.Chats.Add(newChat2);
                db.SaveChanges();
            }
            catch
            {
                ModelState.AddModelError("", "This message cannot save.");
            }
            return(null);
        }
예제 #6
0
        public ActionResult Allocate(int[] check, string Id)
        {
            string content = System.IO.File.ReadAllText(Server.MapPath("~/assets/template/Mailtemplate.html"));
            var    list    = db.Users.ToList();
            var    LectId  = int.Parse(Id);
            //Lấy thông tin group của lecture
            var    myLect   = db.Groups.Where(h => h.id == LectId).FirstOrDefault();
            string LectName = myLect.User.Profile.Name;

            content = content.Replace("{{TutorName}}", LectName);
            //kiểm tra danh sách học sinh gửi vào có rỗng hay k?
            if (check == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            //Nếu ko rỗng
            if (myLect != null)
            {
                //Lấy thông tin danh sách member của group do 1 Lecture đảm nhận
                var myGroupmember = db.GroupMembers.Where(h => h.Group.id == myLect.id).FirstOrDefault();

                //nếu chưa có member
                if (myGroupmember == null)
                {
                    foreach (var mem in check)
                    {
                        if (isAllocated(mem))
                        {
                            var         user   = db.Users.Where(h => h.id == mem).FirstOrDefault();
                            GroupMember member = new GroupMember();
                            member.Group     = myLect;
                            member.idStudent = mem;

                            //content = content.Replace("{{StudentName}}", user.Profile.Name);
                            //content = content.Replace("{{TutorName}}", LectName);
                            //new MailHelper().SendMail(user.Profile.Email, "Allocate Information", content);
                            //new MailHelper().SendMail(myLect.User.Profile.Email, "Allocate Information", content);
                            db.GroupMembers.Add(member);
                            user.GroupMember = member;
                            db.SaveChanges();
                        }
                        else
                        {
                            var user      = db.Users.Where(h => h.id == mem).FirstOrDefault();
                            var myStudent = db.GroupMembers.Where(h => h.idStudent == mem).FirstOrDefault();
                            myStudent.Group = myLect;

                            //content = content.Replace("{{StudentName}}", user.Profile.Name);
                            //content = content.Replace("{{TutorName}}", LectName);
                            //new MailHelper().SendMail(user.Profile.Email, "Allocate Information", content);
                            //new MailHelper().SendMail(myLect.User.Profile.Email, "Allocate Information", content);
                            db.SaveChanges();
                        }
                    }
                }

                else if (myGroupmember != null)
                {
                    foreach (var mem in check)
                    {
                        if (isDuplicate(mem, myLect))
                        {
                            if (isAllocated(mem))
                            {
                                var         user      = db.Users.Where(h => h.id == mem).FirstOrDefault();
                                GroupMember newMember = new GroupMember();
                                newMember.idStudent = mem;
                                newMember.Group     = myLect;
                                db.GroupMembers.Add(newMember);

                                //content = content.Replace("{{StudentName}}", user.Profile.Name);
                                //content = content.Replace("{{TutorName}}", LectName);
                                //new MailHelper().SendMail(user.Profile.Email, "Allocate Information", content);
                                //new MailHelper().SendMail(myLect.User.Profile.Email, "Allocate Information", content);
                                db.SaveChanges();
                            }
                            else
                            {
                                var user      = db.Users.Where(h => h.id == mem).FirstOrDefault();
                                var myStudent = db.GroupMembers.Where(h => h.idStudent == mem).FirstOrDefault();
                                myStudent.Group = myLect;

                                //content = content.Replace("{{StudentName}}", user.Profile.Name);
                                //content = content.Replace("{{TutorName}}", LectName);
                                //new MailHelper().SendMail(user.Profile.Email, "Allocate Information", content);
                                //new MailHelper().SendMail(myLect.User.Profile.Email, "Allocate Information", content);
                                db.SaveChanges();
                            }
                        }
                    }
                }
            }

            return(View(list));
        }