コード例 #1
0
        public ActionResult Create(TraineeCourse traineeCourse)
        {
            var newTraineeCourse = new TraineeCourse
            {
                TraineeId = traineeCourse.TraineeId,
                CourseId  = traineeCourse.CourseId
            };

            _context.TraineeCourses.Add(newTraineeCourse);
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #2
0
        // GET: Trainees/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TraineeCourse trainee = db.TraineeCourses.Find(id);

            if (trainee == null)
            {
                return(HttpNotFound());
            }
            return(View(trainee));
        }
コード例 #3
0
        public ActionResult Certificate(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TraineeCourse trainee = db.TraineeCourses.Include(t => t.Trainee).Include(t => t.Batch).Include(t => t.Course).Include(t => t.UserDetail).FirstOrDefault(a => a.TraineeCourseId == id);

            if (trainee == null)
            {
                return(View("Index"));
            }
            return(View(trainee));
        }
コード例 #4
0
        public ActionResult Edit(TraineeCourse traineeCourse)
        {
            var traineeInDb = _context.TraineeCourses.SingleOrDefault(traineeindb => traineeindb.Id == traineeCourse.Id);

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

            traineeInDb.CourseId = traineeCourse.CourseId;

            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #5
0
        public ActionResult AssignTrainee(AssignViewModel model)
        {
            var traineeCourse = new TraineeCourse()
            {
                TraineeID = model.TraineeId,
                CourseID  = model.Course.Id,
            };

            if (_context.TraineeCourses.Any(t => t.CourseID == model.Course.Id && t.TraineeID == model.TraineeId))
            {
                ModelState.AddModelError("Validation", "It's existed before");
                return(View(model));
            }
            _context.TraineeCourses.Add(traineeCourse);
            _context.SaveChanges();
            return(RedirectToAction("Assign", "Staff", new { @id = model.Course.Id }));
        }
コード例 #6
0
        public ActionResult Edit(TraineeCourse traineeCourse)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var tcInDb = _context.TraineeCourses.SingleOrDefault(p => p.Id == traineeCourse.Id);

            if (tcInDb == null)
            {
                return(HttpNotFound());
            }
            tcInDb.CourseId = traineeCourse.CourseId;

            _context.SaveChanges();

            return(RedirectToAction("Index"));
        }
コード例 #7
0
        public ActionResult Create(TraineeCourse traineeCourse)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            var checkTraineeCourses = _context.TraineeCourses.Any(c => c.TraineeId == traineeCourse.TraineeId &&
                                                                  c.CourseId == traineeCourse.CourseId);

            //Check if Trainer Name or Topic Name existed or not
            if (checkTraineeCourses == true)
            {
                return(View("~/Views/TraineeCourses/Error.cshtml"));
            }
            var newTraineeCourse = new TraineeCourse
            {
                TraineeId = traineeCourse.TraineeId,
                CourseId  = traineeCourse.CourseId
            };

            _context.TraineeCourses.Add(newTraineeCourse);
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #8
0
 public ActionResult ResultAdd(TraineeCourse aTraineeCourse)
 {
     if (ModelState.IsValid)
     {
         if (string.IsNullOrEmpty(aTraineeCourse.Result))
         {
             ViewBag.Result = "Result is Required!!!";
             return(View());
         }
         if (aTraineeCourse.TraineeCourseId == 0)
         {
             ViewBag.Result = "Please Search a Valid Trainee";
             return(View());
         }
         var traineeCourse = db.TraineeCourses.FirstOrDefault(a => a.TraineeCourseId == aTraineeCourse.TraineeCourseId);
         traineeCourse.Result          = aTraineeCourse.Result;
         db.Entry(traineeCourse).State = EntityState.Modified;
         db.SaveChanges();
         ViewBag.Result = "Result Saved";
         return(View());
     }
     ViewBag.Result = "Result Not Saved";
     return(View());
 }
コード例 #9
0
        public ActionResult Create(int?TraineeId, string TraineeName, string TraineeImage, string FatherName, string MotherName, string Gender, string Age, string Address, string ContactNumber, string Email, string NationalIdCard, string TraineeCode, int?CourseId, int?BatchId, HttpPostedFileBase file)
        {
            //if (ModelState.IsValid)
            //{ TraineeCourseId,TraineeCode,TraineeId,CourseId,BatchId,Result,UserDetailsId
            //    db.Trainees.Add(trainee);
            //    db.SaveChanges();
            //    return RedirectToAction("Index");
            //}

            //ViewBag.BatchId = new SelectList(db.Batches, "BatchId", "BatchCode", trainee.BatchId);
            //ViewBag.UserDetailsId = new SelectList(db.UserDetails, "UserDetailsId", "UserName", trainee.UserDetailsId);
            //return View(trainee);
            bool   Status     = false;
            string message    = "";
            var    courseList = db.Courses.ToList();

            if (ModelState.IsValid)
            {
                int  totalTraining           = db.TraineeCourses.Count(a => a.TraineeId == TraineeId);
                bool isThisCourseAlreadyDone = db.TraineeCourses.Any(a => a.TraineeId == TraineeId && a.CourseId == CourseId);
                if (CourseId == null)
                {
                    ViewBag.Required = "PLease Select a Course";
                    ViewBag.Courses  = courseList;
                    return(View());
                }
                if (BatchId == null)
                {
                    ViewBag.Required = "PLease Select a Batch";
                    ViewBag.Courses  = courseList;
                    return(View());
                }
                if (isThisCourseAlreadyDone)
                {
                    ViewBag.Required = "This Trainee Already Done This Course";
                    ViewBag.Courses  = courseList;
                    return(View());
                }
                if (totalTraining >= 3)
                {
                    ViewBag.Required = "This Trainee Already Done 3(Three) Courses";
                    ViewBag.Courses  = courseList;
                    return(View());
                }
                bool isThisCourseCodeAlreadyHas = db.TraineeCourses.Any(a => a.TraineeCode == TraineeCode);
                if (isThisCourseCodeAlreadyHas)
                {
                    ViewBag.Required = "This Trainee Code Already Given";
                    ViewBag.Courses  = courseList;
                    return(View());
                }
                #region Image
                var path = "";
                if (file != null)
                {
                    if (file.ContentLength > 0)
                    { //for checking uploaded file is image or not
                        if ((Path.GetExtension(file.FileName).ToLower() == ".jpg") ||
                            (Path.GetExtension(file.FileName).ToLower() == ".png") ||
                            (Path.GetExtension(file.FileName).ToLower() == ".gif") ||
                            (Path.GetExtension(file.FileName).ToLower() == ".jpeg"))
                        {
                            if (file.ContentLength > 307200) //300kb
                            {
                                ViewBag.SizeConflict = true;
                                ViewBag.Courses      = courseList;
                                ViewBag.Required     = "Maximum Picture Size 300 KB!!!";
                                return(View());
                            }
                            string fileName  = Path.GetFileNameWithoutExtension(file.FileName);
                            string extention = Path.GetExtension(file.FileName);
                            fileName = fileName + DateTime.Now.ToString("yymmssfff") + extention;
                            path     = "~/Content/TraineeImages/" + fileName;
                            fileName = Path.Combine(Server.MapPath("~/Content/TraineeImages/"), fileName);
                            file.SaveAs(fileName);
                            ViewBag.UploadSuccess = true;
                        }
                    }
                    #endregion

                    Trainee aTrainee = new Trainee()
                    {
                        TraineeId       = TraineeId == null ? 0 : (int)TraineeId,
                        TraineeName     = TraineeName,
                        TraineeImage    = path,
                        FatherName      = FatherName,
                        MotherName      = MotherName,
                        Gender          = Gender,
                        Age             = Convert.ToDouble(Age),
                        Address         = Address,
                        ContactNumber   = ContactNumber,
                        Email           = Email,
                        NationalIdCard  = NationalIdCard,
                        UserDetailsId   = Convert.ToInt32(Session["UserDetailsId"]),
                        CreatedDateTime = DateTime.Now
                    };
                    #region Email and NID already Exists or Not!

                    var isExist = aTrainee.TraineeId >= 0?false:IsEmailExist(Email);
                    if (isExist)
                    {
                        ViewBag.Required = "This Email Already Used";
                        ViewBag.Courses  = courseList;
                        //ModelState.AddModelError("EmailExist", "Email already exist");
                        return(View());
                    }

                    var NIDExist = aTrainee.TraineeId >= 0 ? false : IsNIDExist(NationalIdCard);
                    if (NIDExist)
                    {
                        ViewBag.Required = "This National Id Card Already Used";
                        ViewBag.Courses  = courseList;
                        //ModelState.AddModelError("NIDRepeat", "NID already exist");
                        return(View());
                    }
                    var phoneExist = aTrainee.TraineeId >= 0 ? false : IsPhoneExist(ContactNumber);
                    if (phoneExist)
                    {
                        ViewBag.Required = "This Contact Number Already Used";
                        ViewBag.Courses  = courseList;
                        //ModelState.AddModelError("NIDRepeat", "NID already exist");
                        return(View());
                    }
                    TraineeCourse aTraineeCourse = new TraineeCourse()
                    {
                        TraineeCode     = TraineeCode,
                        TraineeId       = TraineeId == null?0:(int)TraineeId,
                        CourseId        = CourseId == null ? 0 : (int)CourseId,
                        BatchId         = BatchId == null ? 0 : (int)BatchId,
                        Result          = "",
                        UserDetailsId   = Convert.ToInt32(Session["UserDetailsId"]),
                        CreatedDateTime = DateTime.Now
                    };
                    if (aTrainee.TraineeId == 0)
                    {
                        aTraineeCourse.Trainee = aTrainee;
                    }
                    #endregion
                    db.TraineeCourses.Add(aTraineeCourse);
                    db.SaveChanges();
                    ViewBag.Required = "Trainee Saved";

                    ViewBag.Courses = courseList;
                    return(View());
                }
            }
            else
            {
                message         = "Invalid Request";
                ViewBag.Courses = courseList;
                return(View());
            }

            //ViewBag.BatchId = new SelectList(db.Batches, "BatchId", "BatchCode", trainee.BatchId);
            //ViewBag.UserDetailsId = new SelectList(db.UserDetails, "UserDetailsId", "UserName", trainee.UserDetailsId);
            ViewBag.Required = "Please Provide All Information";
            ViewBag.Courses  = courseList;
            return(View());
        }