コード例 #1
0
ファイル: AccountController.cs プロジェクト: Maskey2/CMPS411
        public IActionResult Register(User model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var user = new User
            {
                FirstName = model.FirstName,
                LastName  = model.LastName,
                SeluEmail = model.SeluEmail,
                Password  = model.Password,
                MajorId   = 1,
                RoleId    = 1
            };

            _context.User.Add(user);
            _context.SaveChanges();

            var projectRootPath = _environment.WebRootPath;

            var pathToFile = _environment.WebRootPath
                             + Path.DirectorySeparatorChar.ToString()
                             + "Template"
                             + Path.DirectorySeparatorChar.ToString()
                             + "EmailTemplate.html";

            string subject = "LionUp Registration";

            var builder = new BodyBuilder();

            using (StreamReader SourceReader = System.IO.File.OpenText(pathToFile))
            {
                builder.HtmlBody = SourceReader.ReadToEnd();
            }

            string messageBody = string.Format(builder.HtmlBody,
                                               subject,
                                               String.Format("{0:dddd, d MMMM yyyy}", DateTime.Now),
                                               model.FirstName,
                                               model.SeluEmail
                                               );

            _emailService.SendEmail(model.SeluEmail, subject, messageBody);

            return(Ok(model));
        }
コード例 #2
0
ファイル: EventsController.cs プロジェクト: Biratlc/LionUp
        public IActionResult PostEvent(Event model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                model.UserId   = 1;
                model.IsActive = true;

                _context.Event.Add(model);
                _context.SaveChanges();

                return(Ok(model));
            }
            catch { throw; }
        }
コード例 #3
0
ファイル: SeedData.cs プロジェクト: Biratlc/LionUp
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new LionUpContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <LionUpContext> >()))
            {
                //Look up for Majors
                if (context.Major.Any())
                {
                    return; //DB has been seeded
                }

                context.Major.AddRange(
                    new Major
                {
                    MajorCategory = "Accounting"
                },
                    new Major
                {
                    MajorCategory = "Biology"
                },
                    new Major
                {
                    MajorCategory = "Biochemistry"
                },
                    new Major
                {
                    MajorCategory = "Chemistry"
                },
                    new Major
                {
                    MajorCategory = "Computer Science"
                },
                    new Major
                {
                    MajorCategory = "Economics"
                },
                    new Major
                {
                    MajorCategory = "English"
                },
                    new Major
                {
                    MajorCategory = "Health and Kinesiology"
                },
                    new Major
                {
                    MajorCategory = "History"
                },
                    new Major
                {
                    MajorCategory = "Information Technology"
                },
                    new Major
                {
                    MajorCategory = "Physics",
                },
                    new Major
                {
                    MajorCategory = "Mathematics",
                }
                    );


                //Look up for courses
                //if (context.Course.Any())
                //{
                //    return;  //DB has already been seeded
                //}

                //context.Course.AddRange(
                //    new Course
                //    {
                //        CourseCode = "CMPS 161",
                //        CourseName = "Algorithm DSGN/IMPLMNT I",
                //        MajorId = 8
                //    },
                //    new Course
                //    {
                //        CourseCode = "CMPS 280",
                //        CourseName = "Algorithm DSGN/IMPLMNT II",
                //        MajorId = 8
                //    },
                //    new Course
                //    {
                //        CourseCode = "CMPS 285",
                //        CourseName = "Software Engineering",
                //        MajorId = 8
                //    },
                //    new Course
                //    {
                //        CourseCode = "CMPS 290",
                //        CourseName = "Computer Organization",
                //        MajorId = 8
                //    },
                //    new Course
                //    {
                //        CourseCode = "CMPS 390",
                //        CourseName = "Data Structure",
                //        MajorId = 8
                //    },
                //    new Course
                //    {
                //        CourseCode = "CMPS 401",
                //        CourseName = "Survey of Programming Languages",
                //        MajorId = 8
                //    },
                //    new Course
                //    {
                //        CourseCode = "CMPS 411",
                //        CourseName = "Capstone I",
                //        MajorId = 8
                //    },
                //    new Course
                //    {
                //        CourseCode = "CMPS 431",
                //        CourseName = "Operating System",
                //        MajorId = 8
                //    },
                //    new Course
                //    {
                //        CourseCode = "CMPS 479",
                //        CourseName = "Automata",
                //        MajorId = 8
                //    },
                //    new Course
                //    {
                //        CourseCode = "Math 200",
                //        CourseName = "Calculus I",
                //        MajorId = 15
                //    }
                //);


                context.SaveChanges();
            }
        }