Example #1
0
        public ActionResult Update(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }

            using (var db = new SpecialtySelectorDbContext())
            {
                var subject = db.Subjects.Find(id);
                var adminId = this.User.Identity.GetUserId();

                if (subject == null)
                {
                    return(HttpNotFound());
                }

                var updateSubjectModel = new UpdateSubject
                {
                    AdminId     = adminId,
                    Id          = subject.Id,
                    Name        = subject.Name,
                    Description = subject.Description,
                    Credits     = subject.Credits,
                    Course      = subject.Course,
                    Teachers    = subject.Teachers,
                    Specialties = subject.Specialties,
                    IsMandatory = subject.IsMandatory,
                    DeletedOn   = subject.DeletedOn
                };

                return(View(updateSubjectModel));
            }
        }
        private void barBtnUpdateSubject_ItemClick(object sender, ItemClickEventArgs e)
        {
            UpdateSubject aFrmTsk = new UpdateSubject();

            try
            {
                aFrmTsk.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #3
0
        public ActionResult Update(UpdateSubject updateSubject)
        {
            if (ModelState.IsValid && updateSubject != null)
            {
                using (var db = new SpecialtySelectorDbContext())
                {
                    var subjects = db.Subjects.
                                   Find(updateSubject.Id);

                    var adminId = this.User.Identity.GetUserId();

                    var listOfTeachers    = new List <Teacher>();
                    var listOfSpecialties = new List <Specialty>();

                    if (updateSubject.Teacher != null)
                    {
                        foreach (var teacher in updateSubject.Teacher)
                        {
                            var currentTeacher = db.Teachers.FirstOrDefault(t => t.Id == teacher);
                            listOfTeachers.Add(currentTeacher);
                        }
                    }

                    if (updateSubject.Specialty != null)
                    {
                        foreach (var specialty in updateSubject.Specialty)
                        {
                            var currentSpecialty = db.Specialties.FirstOrDefault(s => s.Id == specialty);
                            listOfSpecialties.Add(currentSpecialty);
                        }
                    }

                    subjects.AdminId     = adminId;
                    subjects.Name        = updateSubject.Name;
                    subjects.Description = updateSubject.Description;
                    subjects.Course      = updateSubject.Course;
                    subjects.Credits     = updateSubject.Credits;
                    subjects.IsMandatory = updateSubject.IsMandatory;
                    subjects.DeletedOn   = updateSubject.DeletedOn;
                    subjects.Specialties = listOfSpecialties;
                    subjects.Teachers    = listOfTeachers;
                    subjects.Id          = updateSubject.Id;

                    db.SaveChanges();
                }

                return(RedirectToAction("Details", new { id = updateSubject.Id }));
            }

            return(View(updateSubject));
        }
Example #4
0
        public IActionResult Edit(UpdateSubject model)
        {
            if (ModelState.IsValid)
            {
                if (subjectRepository.UpdateSubject(model) > 0)
                {
                    return(RedirectToAction("Index", "Subject"));
                }
                ModelState.AddModelError("", "System error, please try again later!");
            }
            var subjectEdit = new UpdateSubject();

            return(View(subjectEdit));
        }
Example #5
0
        public IActionResult Edit(int id)
        {
            var subject     = subjectRepository.GetSubject(id);
            var editSubject = new UpdateSubject();

            if (subject != null)
            {
                editSubject.SubjectId   = subject.SubjectId;
                editSubject.SubjectName = subject.SubjectName;
                editSubject.MajorId     = subject.MajorId;
                editSubject.Major       = subjectRepository.GetMajors();
            }
            return(View(editSubject));
        }
Example #6
0
        public int UpdateSubject(UpdateSubject model)
        {
            var subject = GetSubject(model.SubjectId);

            if (subject == null)
            {
                return(-1);
            }
            subject.SubjectName = model.SubjectName;
            subject.MajorId     = model.MajorId;

            context.Update(subject);
            return(context.SaveChanges());
        }
Example #7
0
        public async Task <object> Put(UpdateSubject request)
        {
            var response = new BaseResponse();
            Expression <Func <Subject, bool> > keySelector = x => x.Id == request.Id;
            var entity = await _subjectService.GetById(keySelector : keySelector);

            request.ToEntity(entity);
            var result = await _subjectService.Update(entity);

            response.Success    = true;
            response.Message    = "Update subject succees";
            response.StatusCode = (int)HttpStatusCode.OK;
            response.Results    = result;
            return(response);
        }