public bool Save(CourseCategory objectFirst)
        {
            MySoftCorporationDbContext mySoftCorporationDbContext = new MySoftCorporationDbContext();

            mySoftCorporationDbContext.CourseCategories.Add(objectFirst);
            return(mySoftCorporationDbContext.SaveChanges() > 0);
        }
Beispiel #2
0
        public async Task <IActionResult> Edit(int id, [Bind("CourseCategoryId,Title")] CourseCategory courseCategory)
        {
            if (id != courseCategory.CourseCategoryId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(courseCategory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CourseCategoryExists(courseCategory.CourseCategoryId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(courseCategory));
        }
        public bool Delete(CourseCategory objectFirst)
        {
            MySoftCorporationDbContext mySoftCorporationDbContext = new MySoftCorporationDbContext();

            mySoftCorporationDbContext.Entry(objectFirst).State = EntityState.Deleted;
            return(mySoftCorporationDbContext.SaveChanges() > 0);
        }
Beispiel #4
0
        private List <CourseCategory> GetCourseList()
        {
            var html = new HtmlDocument();

            html.LoadHtml(_view.WebBrowser.DocumentText);
            var document         = html.DocumentNode;
            var categoryHeaders  = document.QuerySelectorAll(".categoryHeader");
            var courseCategories = new List <CourseCategory>();

            foreach (var categoryHeader in categoryHeaders)
            {
                var courseList     = new List <Course>();
                var courseCategory = new CourseCategory();
                courseCategory.Id   = categoryHeader.Id;
                courseCategory.Name = categoryHeader.QuerySelector(".title").InnerText.Trim();
                var courseNodeList = (document.QuerySelector(String.Format("#{0}", courseCategory.Id)).NextSibling).NextSibling.QuerySelectorAll("td.title");
                foreach (var node in courseNodeList)
                {
                    var course = new Course();
                    course.Url  = String.Format("{0}{1}", "http://www.pluralsight.com", node.QuerySelector("a").Attributes["href"].Value);
                    course.Name = node.QuerySelector("a").InnerText.Trim();
                    courseList.Add(course);
                }
                courseCategory.CourseList = courseList;
                courseCategories.Add(courseCategory);
            }
            return(courseCategories);
        }
        public List <CourseCategory> getAllCategory()
        {
            SqlConnection         conn     = new SqlConnection();
            List <CourseCategory> toReturn = new List <CourseCategory>();

            try
            {
                conn = new SqlConnection();
                string connstr = ConfigurationManager.ConnectionStrings["DBConnectionString"].ToString();
                conn.ConnectionString = connstr;
                conn.Open();
                SqlCommand comm = new SqlCommand();
                comm.Connection  = conn;
                comm.CommandText = "select * from [Elearn_courseCategory]";
                SqlDataReader dr = comm.ExecuteReader();
                while (dr.Read())
                {
                    CourseCategory cc = new CourseCategory();
                    cc.categoryID = (int)dr["categoryID"];
                    cc.category   = (string)dr["category"];
                    cc.status     = (string)dr["status"];
                    toReturn.Add(cc);
                }
                dr.Close();
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            return(toReturn);
        }
Beispiel #6
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync(string[] selectedCategories)
        {
            var newStudent = new Student();

            if (selectedCategories != null)
            {
                newStudent.CourseCategories = new List <CourseCategory>();
                foreach (var cat in selectedCategories)
                {
                    var catToAdd = new CourseCategory
                    {
                        CategoryID = int.Parse(cat)
                    };
                    newStudent.CourseCategories.Add(catToAdd);
                }
            }
            if (await TryUpdateModelAsync <Student>(
                    newStudent,
                    "Student",
                    i => i.Nume, i => i.Prenume,
                    i => i.An_studiu, i => i.FirstYear, i => i.TutoreID))
            {
                _context.Student.Add(newStudent);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            PopulateAssignedCategoryData(_context, newStudent);
            return(Page());
        }
        public async Task <IHttpActionResult> PutCourseCategory(int id, CourseCategory courseCategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != courseCategory.CourseCategoryId)
            {
                return(BadRequest());
            }

            db.Entry(courseCategory).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CourseCategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public CourseCategory getCategoryByID(int categoryID)
        {
            SqlConnection  conn     = new SqlConnection();
            CourseCategory toReturn = new CourseCategory();

            try
            {
                conn = new SqlConnection();
                string connstr = ConfigurationManager.ConnectionStrings["DBConnectionString"].ToString();
                conn.ConnectionString = connstr;
                conn.Open();
                SqlCommand comm = new SqlCommand();
                comm.Connection  = conn;
                comm.CommandText = "select * from [Elearn_courseCategory] where categoryID=@categoryID";
                comm.Parameters.AddWithValue("@categoryID", categoryID);
                SqlDataReader dr = comm.ExecuteReader();
                while (dr.Read())
                {
                    toReturn.categoryID = (int)dr["categoryID"];
                    toReturn.category   = (string)dr["category"];
                    toReturn.status     = (string)dr["status"];
                }
                dr.Close();
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            return(toReturn);
        }
Beispiel #9
0
        public ActionResult Create([Bind(Include = "CourseName,Description,CreateAt")] Cours cours, int CategoryId)
        {
            if (ModelState.IsValid)
            {
                CourseCategory category = db.CourseCategories.Find(CategoryId);
                Cours          course   = new Cours();

                course.CourseCategory = category;

                course.CourseName  = cours.CourseName;
                course.Description = cours.Description;
                course.CreateAt    = cours.CreateAt;
                course.CategoryId  = CategoryId;

                db.Courses.Add(course);


                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Id = new SelectList(db.CourseCategories, "Id", "CategName", cours.Id);
            ViewBag.Id = new SelectList(db.Trainee_Course, "Id", "Id", cours.Id);
            return(View(cours));
        }
Beispiel #10
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public JsonResult Update(CourseCategory entity)
        {
            ModelState.Remove("CreatedTime");
            ModelState.Remove("UpdatedTime");
            ModelState.Remove("IsDelete");
            if (ModelState.IsValid)
            {
                var model = ICourseCategoryService.Find(entity.ID);
                if (model == null || (model != null && model.IsDelete))
                {
                    return(DataErorrJResult());
                }

                if (ICourseCategoryService.IsExits(x => x.Name == entity.Name && x.ID != entity.ID))
                {
                    return(JResult(Core.Code.ErrorCode.store_city__namealready_exist, ""));
                }

                model.Name = entity.Name;
                model.Sort = entity.Sort;
                var result = ICourseCategoryService.Update(model);
                return(JResult(result));
            }
            else
            {
                return(ParamsErrorJResult(ModelState));
            }
        }
Beispiel #11
0
        // GET: CourseCategories/Create
        public ActionResult CreateCategory()
        {
            CourseCategory courseCategory = new CourseCategory();

            courseCategory.CreateAt = System.DateTime.Now;
            return(View(courseCategory));
        }
Beispiel #12
0
        public HttpResponseMessage Add(HttpRequestMessage request, CourseCategoryViewModel category)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                if (!ModelState.IsValid)
                {
                    response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var newCategory = new CourseCategory();

                    newCategory.UpdateCourseCategory(category);

                    _courseCategoryService.CreateCategory(newCategory);

                    _courseCategoryService.SaveCategory();

                    // Update view model
                    category = Mapper.Map <CourseCategory, CourseCategoryViewModel>(newCategory);
                    response = request.CreateResponse(HttpStatusCode.Created, category);
                }

                return response;
            }));
        }
Beispiel #13
0
        public JsonResult CreateCategory(string CCName, string BackImage, string BackLeft, string BackTop, string IsEditPic) //ModelCourseCategory ModCorsCat)
        {
            try
            {
                using (IwillDbEntities Dbc = new IwillDbEntities())
                {
                    if (IsEditPic == "false")
                    {
                        var data         = new CourseCategory();
                        var TempLocation = Server.MapPath("~/Images/Temp/" + BackImage);
                        var DestLocation = Server.MapPath("~/Images/UserImages/" + BackImage);
                        System.IO.File.Copy(TempLocation, DestLocation);
                        System.IO.File.Delete(TempLocation);

                        data.CCName      = CCName;
                        data.CImagePath  = BackImage;
                        data.BackImgLeft = Convert.ToInt32(BackLeft);
                        data.BackImgTop  = Convert.ToInt32(BackTop);
                        data.CreatedOn   = DateTime.Now;
                        data.CreatedBy   = Helper.User.UID;
                        data.IsActive    = true;
                        Dbc.CourseCategories.Add(data);
                        Dbc.SaveChanges();
                        TempData["success"] = "Course Category Back Image has been Created";

                        return(Json("saved", JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        var TempLocation = Server.MapPath("~/Images/Temp/" + BackImage);
                        var DestLocation = Server.MapPath("~/Images/UserImages/" + BackImage);
                        System.IO.File.Copy(TempLocation, DestLocation);
                        System.IO.File.Delete(TempLocation);

                        var data = Dbc.CourseCategories.Where(i => i.CCName.ToLower() == CCName.ToLower().Trim() && i.CreatedBy == Helper.User.UID).FirstOrDefault();
                        if (data != null)
                        {
                            data.CImagePath  = BackImage;
                            data.BackImgLeft = Convert.ToInt32(BackLeft);
                            data.BackImgTop  = Convert.ToInt32(BackTop);
                            data.CreatedOn   = DateTime.Now;
                            Dbc.SaveChanges();
                            //TempData["success"] = "Course Category Back Image has been updated";
                            return(Json("updated", JsonRequestBehavior.AllowGet));
                        }
                        else
                        {
                            throw new Exception("data not found to update course category");
                        }
                    }
                }


                //return Json("Error: not deleted", JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                return(Json("Error: on save<br> " + ex.Message, JsonRequestBehavior.AllowGet));
            }
        }
        public int createCategory(CourseCategory cc) // Insert.
        {
            SqlConnection conn     = null;
            int           toReturn = -1;

            try
            {
                conn = new SqlConnection();
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString;
                conn.Open();
                SqlCommand comm = new SqlCommand();
                comm.Connection  = conn;
                comm.CommandText = "Insert into [Elearn_courseCategory] (category, status) OUTPUT INSERTED.categoryID VALUES (@category, @status)";
                comm.Parameters.AddWithValue("@category", cc.category);
                comm.Parameters.AddWithValue("@status", cc.status);
                toReturn = (Int32)comm.ExecuteScalar();
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            return(toReturn);
        }
        public async Task <Result <CourseCategory> > UpdateAsync(CourseCategory category)
        {
            var categoryDb = _mapper.Map <CourseCategory, CourseCategoryDb>(category);
            var result     = await _courseCategoryServiceDb.UpdateAsync(categoryDb);

            return(result.IsSuccess ? Result <CourseCategory> .Ok(_mapper.Map <CourseCategory>(result.Data))
                : Result <CourseCategory> .Fail <CourseCategory>(result.Message));
        }
Beispiel #16
0
        public ActionResult DeleteConfirmed(int id)
        {
            CourseCategory courseCategory = db.CourseCategories.Find(id);

            db.CourseCategories.Remove(courseCategory);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #17
0
        public virtual async Task <bool> DeleteCategory(CourseCategory courseCategory)
        {
            await _categoryRepository.Delete(_mapper.Map <LMSData.Model.CourseCategory>(courseCategory));

            await _categoryRepository.Save();

            return(true);
        }
Beispiel #18
0
        public ActionResult Create(CourseCategory model)
        {
            _context.CourseCategories.Add(model);
            _context.SaveChanges();

            this.AddNotification("Added a new course category!", NotificationType.SUCCESS);
            return(RedirectToAction("Index"));
        }
Beispiel #19
0
        public ActionResult Delete(int ID)
        {
            CourseCategory            objectFirst = service.GetByID(ID);
            CourseCategoryActionModel model       = new CourseCategoryActionModel();

            PropertyCopy.Copy(objectFirst, model);
            return(PartialView("_Delete", model));
        }
Beispiel #20
0
        public void Create(CreateCourseCategoryDTO dto)
        {
            var courseCategory = new CourseCategory()
            {
                Title = dto.Title
            };

            _repository.Add(courseCategory);
        }
        public void Create(string title)
        {
            var courseCategory = new CourseCategory()
            {
                Title = title
            };

            _repository.Add(courseCategory);
        }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            CourseCategory courseCategory = await db.CourseCategories.FindAsync(id);

            db.CourseCategories.Remove(courseCategory);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public async Task <Result <CourseCategory> > AddAsync(CourseCategory courseCategory)
        {
            courseCategory.Id = Guid.NewGuid().ToString();
            var courseCategoryDb = _mapper.Map <CourseCategory, CourseCategoryDb>(courseCategory);
            var result           = await _courseCategoryServiceDb.AddAsync(courseCategoryDb);

            return(result.IsSuccess ? Result <CourseCategory> .Ok(_mapper.Map <CourseCategory>(result.Data))
                 : Result <CourseCategory> .Fail <CourseCategory>(result.Message));
        }
        public bool Update(CourseCategory objectFirst)
        {
            var oldContext        = new MySoftCorporationDbContext();
            var oldCourseCategory = oldContext.CourseCategories.Find(objectFirst.ID);

            var NewContext = new MySoftCorporationDbContext();

            NewContext.Entry(objectFirst).State = EntityState.Modified;
            return(oldContext.SaveChanges() > 0);
        }
        public void Create(string str)
        {
            //ICourseCategoryRepository repository = null;
            var courseCategory = new CourseCategory()
            {
                Title = str
            };

            _repository.Add(courseCategory);
        }
        public IActionResult CreateCategory(CourseCategory category)
        {
            if (category == null)
            {
                return(NotFound());
            }
            _categoryRepository.Add(category);

            return(Ok(category));
        }
Beispiel #27
0
 public static void UpdateCourseCategory(this CourseCategory category, CourseCategoryViewModel categoryVm)
 {
     category.Name            = categoryVm.Name;
     category.Alias           = string.IsNullOrEmpty(categoryVm.Alias) ? StringHelper.ToUnsignString(categoryVm.Name) : categoryVm.Alias;
     category.DisplayOrder    = categoryVm.DisplayOrder;
     category.Status          = categoryVm.Status;
     category.MetaKeyword     = categoryVm.MetaKeyword;
     category.MetaDescription = categoryVm.MetaDescription;
     category.ShowHome        = categoryVm.ShowHome;
 }
Beispiel #28
0
        public virtual async Task <CourseCategory> UpdateCategory(CourseCategory courseCategory)
        {
            LMSData.Model.CourseCategory category = _mapper.Map <LMSData.Model.CourseCategory>(courseCategory);
            await _categoryRepository.Update(category);

            await _categoryRepository.Save();

            courseCategory = _mapper.Map <Services.Model.CourseCategory>(category);
            return(courseCategory);
        }
Beispiel #29
0
        public ActionResult DeleteCourseCategory(int coursecategoryid)
        {
            CourseCategory delete = coursecategoryrepository.DeleteCourseCategory(coursecategoryid);

            if (delete != null)
            {
                TempData["message"] = string.Format("{0} has been deleted", delete.CourseCategoryName);
            }
            return(RedirectToAction("CourseCategory"));
        }
Beispiel #30
0
 public ActionResult AddCourseCategory(CourseCategory category)
 {
     if (ModelState.IsValid)
     {
         coursecategoryrepository.SaveCourseCategory(category);
         TempData["message"] = string.Format("{0} has been saved", category.CourseCategoryName);
         return(RedirectToAction("CourseCategory"));
     }
     return(View(category));
 }
 public CourseCategory Create(CourseCategory obj)
 {
     throw new NotImplementedException();
 }