示例#1
0
        public ActionResult Create(InducteeModel Inductee)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (InducteeRepo.Create(Inductee))
                    {
                        TrainerModel trainerModel = new TrainerModel()
                        {
                            Email    = Inductee.Email,
                            Name     = Inductee.Name,
                            Password = System.Web.Security.Membership.GeneratePassword(8, 6)
                        };
                        int trainerid       = new Trainer().Create(trainerModel);
                        var user_type_model = new Trainer_UserType_Map_Model()
                        {
                            Map_Trainer_Id  = trainerid,
                            Map_UserType_Id = UserType.Trainee.GetHashCode()
                        };
                        new TrainerTraineeUserMapping().Create(user_type_model);
                        ViewData["SuccessMsg"] = "Trainee created successfully.";
                        return(Redirect("/Inductee"));
                    }
                    else
                    {
                        ViewData["ErrorMsg"] = "Failed to create Trainee.";
                    }
                }
            }
            catch (Exception)
            {
                ViewData["ErrorMsg"] = "Failed to create Trainee.";
            }
            var BatchList = BatchRepo.GetAll().OrderByDescending(b => b.Id);

            ViewBag.BatchList = new SelectList(BatchList, "Id", "Name");
            return(View(Inductee));
        }
示例#2
0
 public void Create(Trainer_UserType_Map_Model map_Model)
 {
     map_Model.Map_Id = db.TrainerTraineeUserMapping.Count() > 0 ? db.TrainerTraineeUserMapping.Max(n => n.Map_Id) + 1 : 1;
     db.TrainerTraineeUserMapping.Add(map_Model);
     db.SaveChanges();
 }