Ejemplo n.º 1
0
 public ExecuterStatus Create(CreateExecuterBindingModel model)
 {
     try
     {
         if (_db.Executers.Any(t => t.MasterId == model.MasterId))
         {
             return(ExecuterStatus.duplicate);
         }
         var executer = _db.Executers.Add(new ExecuterModel
         {
             FirstName          = model.FirstName,
             LastName           = model.LastName,
             MasterId           = model.MasterId,
             CollegeId          = model.CollegeId.Value,
             EducationalGroupId = model.EducationalGroupId.Value,
             Email   = model.Email,
             Phone   = model.Phone,
             Explain = model.Explain,
         });
         _db.SaveChanges();
         if (model.ResearchGroupIds != null)
         {
             foreach (var a in model.ResearchGroupIds)
             {
                 _db.ExecuterResearchGroups.Add(new ExecuterResearchGroupModel
                 {
                     ExeuterId       = executer.Id,
                     ResearchGroupId = a,
                 });
             }
             _db.SaveChanges();
         }
         return(ExecuterStatus.success);
     }
     catch {}
     return(ExecuterStatus.failed);
 }
Ejemplo n.º 2
0
        public ActionResult CreateExecuter(CreateExecuterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.ModelState = ModelState;
            }
            else
            {
                var result = ExecuterManager.Create(model);
                switch (result)
                {
                case ExecuterManager.ExecuterStatus.failed:
                    ViewBag.Failed = Fa.Error;
                    break;

                case ExecuterManager.ExecuterStatus.duplicate:
                    ViewBag.Duplicate = Fa.DuplicateExecuter;
                    break;

                default:
                    return(RedirectToAction("Index"));
                }
            }
            var colleges = CollegeManager.List();

            ViewBag.College = colleges;
            if (colleges.Count > 0)
            {
                ViewBag.EducationalGroup = EducationalGroupManager.FindByCollegeId(colleges.FirstOrDefault().Id);
            }
            else
            {
                ViewBag.EducationalGroup = new List <EducationalGroupModel>();
            }
            return(View(model));
        }