public SpecialtyViewModel(Specialty specialty) : this()
 {
     Id                    = specialty.Id;
     Name                  = specialty.Name;
     Description           = specialty.Description;
     Major                 = new MajorViewModel(specialty.Major);
     StandardOfCertificate = new StandardOfCertificateViewModel(specialty.StandardOfCertificate);
 }
Пример #2
0
 private void CopyToMajor(MajorViewModel majorViewModel, Major major)
 {
     major.Id             = majorViewModel.Id;
     major.Subject        = majorViewModel.Subject;
     major.Status         = majorViewModel.Status;
     major.YearOfGraduate = majorViewModel.YearOfGraduate;
     major.UserId         = majorViewModel.UserId;
 }
Пример #3
0
        private List <string> GetAllPropertyNameOfMajorViewModel()
        {
            var majorViewModel = new MajorViewModel();

            var type = majorViewModel.GetType();

            return(ReflectionUtilities.GetAllPropertyNamesOfType(type));
        }
Пример #4
0
        public ActionResult Create(MajorViewModel majorViewModel)
        {
            if (ModelState.IsValid)
            {
                Save(majorViewModel);
                return(RedirectToAction("Index", new { UserId = majorViewModel.UserId }));
            }

            return(View());
        }
Пример #5
0
        private void UpdateMajor(MajorViewModel majorViewModel)
        {
            var dbContext = new AppDbContext();

            var major = dbContext.Majors.Find(majorViewModel.Id);

            CopyToMajor(majorViewModel, major);

            dbContext.SaveChanges();
        }
Пример #6
0
        private void Save(MajorViewModel majorViewModel)
        {
            var dbContext = new AppDbContext();

            var major = MapToMajor(majorViewModel);

            dbContext.Majors.Add(major);

            dbContext.SaveChanges();
        }
Пример #7
0
        public ActionResult MajorDetail(int?id)
        {
            MajorViewModel model = new MajorViewModel();

            if (id.HasValue)
            {
                model = new MajorRepository().GetByID((int)id);
            }
            return(PartialView("_Major", model));
        }
Пример #8
0
        public ActionResult Edit(MajorViewModel majorViewModel)
        {
            if (ModelState.IsValid)
            {
                UpdateMajor(majorViewModel);

                return(RedirectToAction("Index"));
            }

            return(View());
        }
Пример #9
0
        public async Task <IActionResult> Index()
        {
            var majors = await _majorService.GetAllAsync();

            var viewModel = new MajorViewModel
            {
                Majors = majors
            };

            return(View(viewModel));
        }
 private Major MapToMajor(MajorViewModel majorViewModel)
 {
     return(new Major
     {
         Id = majorViewModel.Id,
         Status = majorViewModel.Status,
         Subject = majorViewModel.Subject,
         UserId = majorViewModel.UserId,
         YearOfGraduate = majorViewModel.YearOfGraduate
     });
 }
Пример #11
0
 public ActionResult UpdateMajor(MajorViewModel major)
 {
     if (ModelState.IsValid)
     {
         var mjor = new Major();
         major.updateMajor(mjor);
         db.Entry(mjor).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("MajorsList"));
     }
     return(View());
 }
Пример #12
0
 public ActionResult CreateMajor(MajorViewModel major)
 {
     if (ModelState.IsValid)
     {
         var newmajor = new Major();
         major.updateMajor(newmajor);
         db.Majors.Add(newmajor);
         db.SaveChanges();
         return(RedirectToAction("MajorsList"));
     }
     return(View());
 }
Пример #13
0
        public JsonResult SaveMajor(MajorViewModel model)
        {
            ResponseData result = new Models.ResponseData();

            if (model.MajID != 0)
            {
                result = new MajorRepository().UpdateByEntity(model);
            }
            else
            {
                result = new MajorRepository().AddByEntity(model);
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Пример #14
0
        public ActionResult MajorsUpdate([DataSourceRequest]DataSourceRequest request, MajorViewModel major)
        {
            var majorExists = this.majors.All().Any(m => m.Name == major.Name);

            if (majorExists)
            {
                this.ModelState.AddModelError("Major exists", "Major will such name already exists.");
            }

            if (this.ModelState.IsValid)
            {
                var entity = this.Mapper.Map<Major>(major);
                this.majors.Update(entity);
            }

            return this.Json(new[] { major }.ToDataSourceResult(request, this.ModelState));
        }
        public ActionResult GetAMajor(int?id)
        {
            MajorViewModel _majorViewModel = new MajorViewModel();

            if (id == null)
            {
                _majorViewModel.DepartmentsList = new SelectList(db.Departments, "DepartmentID", "DepartmentName");

                return(PartialView("_Modal.FormContent", _majorViewModel));
            }

            Major major = db.Majors.Find(id);

            _majorViewModel.MajorID         = major.MajorID;
            _majorViewModel.MajorName       = major.MajorName;
            _majorViewModel.DepartmentsList = new SelectList(db.Departments, "DepartmentID", "DepartmentName", major.DepartmentID);
            return(PartialView("_Modal.FormContent", _majorViewModel));
        }
Пример #16
0
 public ResponseData UpdateByEntity(MajorViewModel newdata)
 {
     using (SATEntities db = new SATEntities())
     {
         ResponseData result = new Models.ResponseData();
         try
         {
             var data = db.tb_Major.Single(x => x.MajID == newdata.MajID);
             data.MajName    = newdata.MajName;
             data.MajStatus  = (newdata.Status == "1") ? true : false;
             data.ModifyBy   = UtilityService.User.UserID;
             data.ModifyDate = DateTime.Now;
             db.SaveChanges();
         }
         catch (Exception)
         {
         }
         return(result);
     }
 }
Пример #17
0
        public ActionResult UpdateMajor(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest));
            }

            Major mj = db.Majors.Find(id);

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

            MajorViewModel major = new MajorViewModel(mj.id, mj.facultyId, mj.name, mj.isInactive);

            ViewBag.facultyList = new SelectList(
                db.Faculties.Select(x => new { Text = x.name, Value = x.id }), "Value", "Text", mj.facultyId);
            return(View(major));
        }
Пример #18
0
        public ActionResult MajorsCreate([DataSourceRequest]DataSourceRequest request, MajorViewModel major)
        {
            var majorExists = this.majors.All().Any(m => m.Name == major.Name);

            if (majorExists)
            {
                this.ModelState.AddModelError("Major exists", "Major with such name already exists.");
            }

            Major result = null;

            if (this.ModelState.IsValid)
            {
                result = this.majors.Create(major.Name);
            }

            if (result != null)
            {
                return this.Json(new[] { result }.ToDataSourceResult(request, this.ModelState));
            }

            return this.Json(new[] { major }.ToDataSourceResult(request, this.ModelState));
        }
Пример #19
0
 public ResponseData AddByEntity(MajorViewModel data)
 {
     using (SATEntities db = new SATEntities())
     {
         ResponseData result = new Models.ResponseData();
         try
         {
             tb_Major model = new tb_Major();
             model.MajID      = data.MajID;
             model.MajName    = data.MajName;
             model.MajStatus  = (data.Status == "1") ? true : false;
             model.CreateBy   = UtilityService.User.UserID;
             model.CreateDate = DateTime.Now;
             model.ModifyBy   = UtilityService.User.UserID;
             model.ModifyDate = DateTime.Now;
             db.tb_Major.Add(model);
             db.SaveChanges();
         }
         catch (Exception)
         {
         }
         return(result);
     }
 }
 public bool Edit(MajorViewModel majorViewModel)
 {
     return(_repository.Edit(MapToMajor(majorViewModel)));
 }
 public bool Create(MajorViewModel majorViewModel)
 {
     return(_repository.Create(MapToMajor(majorViewModel)));
 }
Пример #22
0
        public ActionResult MajorsDestroy([DataSourceRequest]DataSourceRequest request, MajorViewModel major)
        {
            this.majors.Delete(major.Id);

            return this.Json(new[] { major }.ToDataSourceResult(request, this.ModelState));
        }