Example #1
0
        public void Execute(UserDto request)
        {
            validator.ValidateAndThrow(request);
            var user = mapper.Map <User>(request);

            context.Users.Add(user);
            context.SaveChanges();
            sender.Send(new SendEmailDto
            {
                Content = "<h1>You are successfully registrated to online courses!</h1>",
                SendTo  = request.Email,
                Subject = "Registration"
            });

            var userId = user.Id;
            var allow  = new List <int> {
                3, 4, 26, 27
            };

            foreach (var a in allow)
            {
                context.UserUserCase.Add(new UserUserCase {
                    UserId    = userId,
                    UseCaseId = a
                });
            }

            context.SaveChanges();
        }
        private void addEditButton_Click(object sender, RoutedEventArgs e)
        {
            string descriptionSubmodule = new TextRange(rtbEditor.Document.ContentStart, rtbEditor.Document.ContentEnd).Text;

            if (db.submodule.Where(p => p.submoduleId == submoduleID).Any())
            {
                if (submoduleName.Text != "" || descriptionSubmodule != "" || imageArray != null)
                {
                    var submodule = db.submodule.Where(p => p.submoduleId == submoduleID).FirstOrDefault();
                    submodule.submoduleName  = submoduleName.Text;
                    submodule.submoduleText  = descriptionSubmodule;
                    submodule.submoduleImage = imageArray;
                    db.SaveChanges();
                }
            }
            else
            {
                if (submoduleName.Text != "" && descriptionSubmodule != "" && imageArray != null)
                {
                    submodule addSubmodule = new submodule
                    {
                        submoduleName  = submoduleName.Text,
                        submoduleText  = descriptionSubmodule,
                        submoduleImage = imageArray,
                        moduleId       = moduleID
                    };
                    db.submodule.Add(addSubmodule);
                    db.SaveChanges();
                    submoduleName.Clear();
                    submoduleImage.ImageSource = null;
                    rtbEditor.Document.Blocks.Clear();
                }
            }
        }
Example #3
0
        private void addEditButton_Click(object sender, RoutedEventArgs e)
        {
            var answers = db.answer.Where(p => p.answerId == answerID).FirstOrDefault();

            answers.answerText = answerText.Text;
            db.SaveChanges();
            GetAnswer();
        }
        public ActionResult CoursesCreate([Bind(Include = "Id,Code,Name,Section,Credit")] Course course)
        {
            if (ModelState.IsValid)
            {
                db.Courses.Add(course);
                db.SaveChanges();
                return(RedirectToAction("Courses"));
            }

            return(View(course));
        }
        public OrderState ChangeOrderState(Order order)
        {
            Order orderToBeModified = db.Orders.Find(order.OrderId);

            orderToBeModified.OrderState = order.OrderState;
            db.SaveChanges();

            if (orderToBeModified.OrderState == OrderState.Finished)
            {
                this.mailService.SendFinishedOrderEmail(orderToBeModified);
            }

            return(order.OrderState);
        }
Example #6
0
        private void addEditButton_Click(object sender, RoutedEventArgs e)
        {
            string descriptionModule = new TextRange(rtbEditor.Document.ContentStart, rtbEditor.Document.ContentEnd).Text;

            if (db.module.Where(p => p.moduleId == moduleID).Any())
            {
                if (moduleName.Text != "" || descriptionModule != "" || imageArray != null)
                {
                    var module = db.module.Where(p => p.moduleId == moduleID).FirstOrDefault();
                    module.moduleName  = moduleName.Text;
                    module.description = descriptionModule;
                    module.moduleImage = imageArray;
                    db.SaveChanges();
                }
            }
            else
            {
                if (moduleName.Text != "" && descriptionModule != "" && imageArray != null)
                {
                    module addModule = new module
                    {
                        moduleName  = moduleName.Text,
                        description = descriptionModule,
                        moduleImage = imageArray
                    };

                    test addTest = new test
                    {
                        testName = moduleName.Text,
                        moduleId = addModule.moduleId
                    };

                    badge addBadge = new badge
                    {
                        badgeName  = moduleName.Text,
                        badgeImage = imageArray,
                        moduleId   = addModule.moduleId
                    };

                    db.module.Add(addModule);
                    db.test.Add(addTest);
                    db.badge.Add(addBadge);
                    db.SaveChanges();
                }
                moduleName.Clear();
                moduleImage.ImageSource = null;
                rtbEditor.Document.Blocks.Clear();
            }
        }
Example #7
0
        private void GetBadge()
        {
            var badgeId    = db.badge.Where(p => p.moduleId == moduleId).Select(p => p.badgeId).FirstOrDefault();
            var resultTest = db.result.Where(p => p.userId == MainWindow.userIdToTest && p.badgeId == badgeId).Any();

            if (resultTest)
            {
                var image = ConvertToImage.ToImage(db.badge.Where(p => p.moduleId == moduleId).Select(p => p.badgeImage).FirstOrDefault());
                badgeImage.Source = image;
                dialogEnd.IsOpen  = true;
            }
            else
            {
                var image = ConvertToImage.ToImage(db.badge.Where(p => p.moduleId == moduleId).Select(p => p.badgeImage).FirstOrDefault());
                badgeImage.Source = image;
                dialogEnd.IsOpen  = true;
                result finishTest = new result
                {
                    badgeId = badgeId,
                    userId  = MainWindow.userIdToTest
                };
                db.result.Add(finishTest);
                db.SaveChanges();
            }
        }
Example #8
0
 private void delButton_Click(object sender, RoutedEventArgs e)
 {
     if (answerID != 0)
     {
         db = new CoursesContext();
         CoursesContext db1 = new CoursesContext();
         if (db1.correctAnswer.Where(p => p.answer == answerID).Any())
         {
             correctAnswer correctAnswers = new correctAnswer
             {
                 answer = answerID
             };
             db1.correctAnswer.Attach(correctAnswers);
             db1.correctAnswer.Remove(correctAnswers);
         }
         answer answers = new answer
         {
             answerId = answerID
         };
         db.answer.Attach(answers);
         db.answer.Remove(answers);
         db.SaveChanges();
         answerText.Clear();
         GetAnswer();
     }
 }
        static void Main(string[] args)
        {
            Console.WriteLine("Hello Entity Framework World!");

            var optionsBuilder = new DbContextOptionsBuilder();

            var config = new ConfigurationBuilder()
                         .SetBasePath(Directory.GetCurrentDirectory())
                         .AddJsonFile("appsettings.json")
                         .Build();

            optionsBuilder.UseMySql(config.GetConnectionString("DefaultConnection"));

            var db = new CoursesContext(optionsBuilder.Options);

            var teacher = new Teacher()
            {
                Name = "Aarón"
            };

            var course = new Course()
            {
                Name = "NET Amaris", Teacher = teacher
            };

            db.Courses.Add(course);

            db.SaveChanges();
        }
 private void btRegistration_Click(object sender, RoutedEventArgs e)
 {
     if (tbRegLogin.Text != "" && tbRegPassword.Password != "" && tbSurname.Text != "" && tbFirstname.Text != "" && tbDob.DisplayDate != null && tbSex.SelectedItem != null)
     {
         db = new CoursesContext();
         if (db.users.Where(p => p.userLogin == tbRegLogin.Text).Any())
         {
             tbUnikUser.Visibility = Visibility.Visible;
         }
         else
         {
             users registration = new users
             {
                 userLogin    = tbRegLogin.Text,
                 userPassword = PBKDF2HashHelper.CreatePasswordHash(tbRegPassword.Password, 15000),
                 surname      = tbSurname.Text,
                 firstname    = tbFirstname.Text,
                 dob          = tbDob.DisplayDate,
                 sex          = tbSex.Text
             };
             db.users.Add(registration);
             db.SaveChanges();
             dialogDone.IsOpen = true;
         }
     }
     else
     {
         tbNotNull.Visibility = Visibility.Visible;
     }
 }
Example #11
0
        public Order CreateOrder(Order newOrder, string userId)
        {
            var cart = GetCart();

            newOrder.OrderDate = DateTime.Now;
            newOrder.UserId    = userId;
            db.Orders.Add(newOrder);
            if (newOrder.OrderItems == null)
            {
                newOrder.OrderItems = new List <OrderItem>();
            }
            decimal cartValue = 0;

            foreach (var cartItem in cart)
            {
                var newOrderItem = new OrderItem()
                {
                    CourseId      = cartItem.Course.CourseId,
                    Quatity       = cartItem.Quantity,
                    PurchaseValue = cartItem.Course.CoursePrice
                };

                cartValue += (cartItem.Quantity * cartItem.Course.CoursePrice);
                newOrder.OrderItems.Add(newOrderItem);
            }
            newOrder.OrderValue = cartValue;
            db.SaveChanges();

            return(newOrder);
        }
Example #12
0
        private void buttonAddCourse_Click(object sender, EventArgs e)
        {
            if (nameTB.Text == String.Empty || surnameTB.Text == String.Empty || sexLB.SelectedIndex == -1)
            {
                MessageBox.Show(this, "Incorrect data", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var lecturerToAdd = new Lecturer {
                Name = nameTB.Text, Surname = surnameTB.Text, Sex = sexLB.SelectedItem.ToString(), Birthday = birthdayPicker.Value, Degree = Convert.ToInt32(degreeNumeric.Value)
            };

            try
            {
                using (CoursesContext context = new CoursesContext())
                {
                    context.Lecturers.Add(lecturerToAdd);
                    context.SaveChanges();
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public void Execute(LectureDto request)
        {
            _validator.ValidateAndThrow(request);
            var lecture = _mapper.Map <Lecture>(request);

            _context.Lectures.Add(lecture);
            _context.SaveChanges();
        }
        public void Execute(CourseDto request)
        {
            _validator.ValidateAndThrow(request);
            var course = _mapper.Map <Course>(request);

            _context.Courses.Add(course);

            _context.SaveChanges();
        }
        public void Execute(CategoryDto request)
        {
            _validator.ValidateAndThrow(request);
            var category = _mapper.Map <Category>(request);

            _context.Categories.Add(category);

            _context.SaveChanges();
        }
Example #16
0
        /// <summary>
        /// Removes organisation from database by its ID
        /// </summary>
        /// <param name="id">Organisation ID</param>
        public void DeleteOrgByID(int id)
        {
            var organisationToDelete = new Organisation {
                ID = id
            };

            try
            {
                context.Organisations.Remove(organisationToDelete);
                context.SaveChanges();
                AttachOrganisations();
                organisations.Update();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public void Execute(TeacherDto request)
        {
            _validator.ValidateAndThrow(request);
            var teacher = _mapper.Map <Teacher>(request);

            _context.Teachers.Add(teacher);

            _context.SaveChanges();
        }
Example #18
0
        public void Execute(UserDto request)
        {
            _validator.ValidateAndThrow(request);
            var user = _mapper.Map <User>(request);

            _context.Users.Add(user);

            _context.SaveChanges();
        }
        public IActionResult PostClass([FromBody] ClassTracker newClass)
        {
            if (newClass == null)
            {
                return(StatusCode(400, "The new class must not be null"));
            }

            databaseConnection.ClassTracker.Add(newClass);
            try
            {
                databaseConnection.SaveChanges();
            }
            catch (DbUpdateException dbe)
            {
                return(StatusCode(500, dbe.Message));
            }

            return(StatusCode(201, newClass));
        }
        public void Log(IUseCase useCase, IApplicationActor actor, object useCaseData)
        {
            context.UseCaseLogs.Add(new UseCaseLog
            {
                Actor       = actor.Identity,
                Data        = JsonConvert.SerializeObject(useCaseData),
                Date        = DateTime.Now,
                UseCaseName = useCase.Name
            });

            context.SaveChanges();
        }
Example #21
0
        public void Execute(int request)
        {
            var userId = actor.Id;
            var sub    = context.UserCourse.Where(x => x.CourseId == request && x.UserId == actor.Id).FirstOrDefault();

            if (sub == null)
            {
                throw new EntityNotFoundException(request, typeof(UserCourse));
            }

            context.UserCourse.Remove(sub);
            context.SaveChanges();
        }
 private void addEditButton_Click(object sender, RoutedEventArgs e)
 {
     if (db.question.Where(p => p.questionId == questionID).Any())
     {
         var questions = db.question.Where(p => p.questionId == questionID).FirstOrDefault();
         questions.questionText = questionText.Text;
         db.SaveChanges();
     }
     else
     {
         question questions = new question
         {
             questionText = questionText.Text,
             testId       = testID
         };
         db.question.Add(questions);
         db.SaveChanges();
     }
     StartProgramm(moduleID);
     dialogQuestion.IsOpen = false;
     questionText.Clear();
     questionID = 0;
 }
        public void Execute(int request)
        {
            var user = _context.Users.Find(request);

            if (user == null)
            {
                throw new EntityNotFoundException(request, typeof(User));
            }

            user.IsDeleted = true;
            user.IsActive  = false;
            user.DeletedAt = DateTime.Now;
            _context.SaveChanges();
        }
Example #24
0
        public void Execute(UserCoursesDto request)
        {
            validator.ValidateAndThrow(request);
            var actorId = _actor.Id;
            var sub     = new UserCourse
            {
                UserId   = actorId,
                CourseId = request.CourseId
            };

            context.UserCourse.Add(sub);

            context.SaveChanges();
        }
        public void Execute(CategoryDto request)
        {
            var id       = request.Id;
            var category = _context.Categories.Find(id);

            if (category == null)
            {
                throw new EntityNotFoundException(id, typeof(CategoryDto));
            }

            _validator.ValidateAndThrow(request);
            _mapper.Map(request, category);
            _context.SaveChanges();
        }
        public void Execute(LectureDto request)
        {
            var id      = request.Id;
            var lecture = _context.Lectures.Find(id);

            if (lecture == null)
            {
                throw new EntityNotFoundException(id, typeof(LectureDto));
            }

            _validator.ValidateAndThrow(request);
            _mapper.Map(request, lecture);
            _context.SaveChanges();
        }
        public void Execute(TeacherDto request)
        {
            var id      = request.Id;
            var teacher = _context.Teachers.Find(id);

            if (teacher == null)
            {
                throw new EntityNotFoundException(id, typeof(TeacherDto));
            }

            _validator.ValidateAndThrow(request);
            _mapper.Map(request, teacher);
            _context.SaveChanges();
        }
Example #28
0
        public void Execute(int request)
        {
            var lecture = _context.Lectures.Find(request);

            if (lecture == null)
            {
                throw new EntityNotFoundException(request, typeof(Lecture));
            }

            lecture.IsDeleted = true;
            lecture.IsActive  = false;
            lecture.DeletedAt = DateTime.Now;
            _context.SaveChanges();
        }
Example #29
0
        public void Update(Lecturer lecturer)
        {
            var lct = db.Lecturers.Where(x => x.LecturerId == lecturer.LecturerId).FirstOrDefault();

            lct.FirstName     = lecturer.FirstName;
            lct.SecondName    = lecturer.SecondName;
            lct.Information   = lecturer.Information;
            lct.LecturerEmail = lecturer.LecturerEmail;
            lct.Image         = lecturer.Image;
            lct.ImageName     = lecturer.ImageName;
            lct.Courses       = lecturer.Courses;
            lct.Department    = lecturer.Department;
            db.SaveChanges();
        }
Example #30
0
        public void Execute(int request)
        {
            var category = _context.Categories.Find(request);

            if (category == null)
            {
                throw new EntityNotFoundException(request, typeof(Category));
            }

            category.IsDeleted = true;
            category.IsActive  = false;
            category.DeletedAt = DateTime.Now;

            _context.SaveChanges();
        }