public ActionResult CoursesEdit([Bind(Include = "Id,Code,Name,Section,Credit")] Course course)
 {
     if (ModelState.IsValid)
     {
         db.Entry(course).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Courses"));
     }
     return(View(course));
 }
Ejemplo n.º 2
0
        public ActionResult AddCourse(EditCourseViewModel model, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                var fileExt  = "";
                var fileName = "";
                if (file != null && file.ContentLength > 0)
                {
                    fileExt  = Path.GetExtension(file.FileName);
                    fileName = Guid.NewGuid() + fileExt;

                    var path = Path.Combine(Server.MapPath(AppConfig.ImageFolder), fileName);
                    file.SaveAs(path);

                    //model.Course.FileOrPicturePhotoName = fileName;
                }

                if (model.Course.CourseId > 0)
                {
                    var oldFileName = Path.Combine(Server.MapPath(AppConfig.ImageFolder), model.Course.FileOrPicturePhotoName);
                    System.IO.File.Delete(oldFileName);

                    model.Course.FileOrPicturePhotoName = fileName;
                    db.Entry(model.Course).State        = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("AddCourse", new { confirmation = true, msg = "Successfully modified!" }));
                }
                else
                {
                    if (!String.IsNullOrEmpty(fileExt))
                    {
                        model.Course.InsertDate             = DateTime.Now;
                        model.Course.FileOrPicturePhotoName = fileName;

                        db.Entry(model.Course).State = EntityState.Added;
                        db.SaveChanges();

                        return(RedirectToAction("AddCourse", new { confirmation = true, msg = "Successfully added!" }));
                    }
                    else
                    {
                        ModelState.AddModelError("", "No image choosen");
                        var categories = db.Categories.ToList();
                        model.Categories = categories;
                        return(View(model));
                    }
                }
            }
            else
            {
                var categories = db.Categories.ToList();
                model.Categories = categories;
                return(View(model));
            }
        }
Ejemplo n.º 3
0
        public virtual void Add(TEntity entity)
        {
            var dbEntityEntry = context.Entry(entity);

            if (dbEntityEntry.State != EntityState.Detached)
            {
                dbEntityEntry.State = EntityState.Added;
            }
            else
            {
                dbSet.Add(entity);
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> PutCourses(long id, Courses courses)
        {
            if (id != courses.Id)
            {
                return(BadRequest());
            }

            _context.Entry(courses).State = EntityState.Modified;

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

            return(NoContent());
        }
 public void Update(Student student)
 {
     db.Entry(student).State = EntityState.Modified;
 }
 public void Update(Department department)
 {
     db.Entry(department).State = EntityState.Modified;
 }
Ejemplo n.º 7
0
 public void Update(Railway t)
 {
     context.Entry <Railway>(t).State = EntityState.Modified;
 }
Ejemplo n.º 8
0
 public void Update(Specialization specialization)
 {
     _db.Entry(specialization).State = EntityState.Modified;
     _db.SaveChanges();
 }
Ejemplo n.º 9
0
 public void Update(Journal journal)
 {
     _db.Entry(journal).State = EntityState.Modified;
     _db.SaveChanges();
 }
Ejemplo n.º 10
0
 public void Update(Course course)
 {
     _db.Entry(course).State = EntityState.Modified;
     _db.SaveChanges();
 }
Ejemplo n.º 11
0
 public void Update(Cartel t)
 {
     context.Entry <Cartel>(t).State = EntityState.Modified;
 }
 public void Update(Topic topic)
 {
     db.Entry(topic).State = EntityState.Modified;
 }
 public void Update(Progress progress)
 {
     db.Entry(progress).State = EntityState.Modified;
 }