예제 #1
0
 public static void clearInput(TeacherEdit formS)
 {
     formS.txtFirstName.Clear();
     formS.txtLastName.Clear();
     formS.txtEmail.Clear();
     formS.txtProfession.Clear();
 }
        public IActionResult Edit(int?id)
        {
            ViewBag.BranchId = new SelectList(_branchService.GetAll(), "BranchId", "BranchName");
            if (id == null)
            {
                return(NotFound());
            }
            var entity = _teacherService.GetById((int)id);

            if (entity == null)
            {
                return(NotFound());
            }
            var model = new TeacherEdit()
            {
                Id              = entity.TeacherId,
                TeacherName     = entity.TeacherName,
                Education       = entity.Education,
                Image           = entity.Image,
                Description     = entity.Description,
                FacebookAdress  = entity.FacebookAdress,
                TwitterAdress   = entity.TwitterAdress,
                InstagramAdress = entity.InstagramAdress,
                BranchId        = entity.BranchId,
            };

            return(View(model));
        }
        public async Task <IActionResult> Edit(TeacherEdit model, IFormFile file)
        {
            if (ModelState.IsValid)
            {
                var entity = _teacherService.GetById(model.Id);

                if (entity == null)
                {
                    return(NotFound());
                }

                entity.TeacherName     = model.TeacherName;
                entity.Education       = model.Education;
                entity.BranchId        = model.BranchId;
                entity.Description     = model.Description;
                entity.FacebookAdress  = model.FacebookAdress;
                entity.TwitterAdress   = model.TwitterAdress;
                entity.InstagramAdress = model.InstagramAdress;

                if (file != null)
                {
                    entity.Image = file.FileName;
                    var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images", file.FileName);
                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        await file.CopyToAsync(stream);
                    }
                }

                _teacherService.Update(entity);
                return(RedirectToAction("TeacherList"));
            }

            return(View(model));
        }
예제 #4
0
        public bool UpdateTeacher(TeacherEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Teachers
                    .Single(e => e.TeacherId == model.TeacherId);
                entity.FirstName = model.FirstName;
                entity.LastName  = model.LastName;
                entity.Bio       = model.Bio;

                return(ctx.SaveChanges() == 1);
            }
        }
예제 #5
0
        // GET: Teacher/Edit/5
        public ActionResult Edit(int id)
        {
            var service = CreateTeacherService();
            var detail  = service.GetTeacherById(id);
            var model   =
                new TeacherEdit
            {
                TeacherId = detail.TeacherId,
                FirstName = detail.FirstName,
                LastName  = detail.LastName,
                Bio       = detail.Bio
            };

            return(View(model));
        }
예제 #6
0
        public ActionResult Edit(int id, TeacherEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.TeacherId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }
            var service = CreateTeacherService();

            if (service.UpdateTeacher(model))
            {
                TempData["SaveResult"] = "Your note was updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Your note could not be updated.");
            return(View(model));
        }