public HttpResponseMessage AddCategory(AddCategoryDTO category)
        {
            dbContext.Categories.Add(new Category
            {
                ImageUrl = category.ImageUrl,
                Name     = category.Name
            });

            dbContext.SaveChanges();

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
        public HttpResponseMessage AddCategory(AddCourseDTO course)
        {
            var newCourse = new Course()
            {
                Name = course.Name,
                Path = course.Path
            };

            dbContext.Courses.Add(newCourse);
            dbContext.SaveChanges();

            foreach (var id in course.CategoriesIds)
            {
                var category = dbContext.Categories.Where(c => c.Id == id).FirstOrDefault();

                if (category != null)
                {
                    newCourse.Categories.Add(category);
                }
            }

            dbContext.SaveChanges();

            foreach (var stage in course.Stages)
            {
                newCourse.Stages.Add(new Stage
                {
                    CourseId    = newCourse.Id,
                    Name        = stage.Name,
                    HtmlContent = stage.HtmlContent,
                    Nr          = stage.Nr
                });
            }

            dbContext.SaveChanges();

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Ejemplo n.º 3
0
        public void AddUser(UserDTO user)
        {
            dbContext
            .Users
            .Add(new Models.User
            {
                Email     = user.Email,
                FirstName = user.FirstName,
                LastName  = user.LastName,
                Username  = user.Username,
                Password  = user.Password
            });

            dbContext.SaveChanges();
        }