예제 #1
0
        public ActionResult Create(TeachersCourseAllocation teachersCourseAllocation)
        {
            string ErrorMessage = "";
            int    count        = 0;

            try
            {
                TeachersCourseAllocation tc = db.TeachersCourseAllocations.FirstOrDefault(
                    p => p.ProgramCourseID == teachersCourseAllocation.ProgramCourseID &&
                    p.TeacherID == teachersCourseAllocation.TeacherID);

                if (tc != null)
                {
                    ViewBag.MessageType = "error";
                    ViewBag.Message     = "Selected Teacher Course is already exists.";
                    ModelState.AddModelError(string.Empty, "Selected Teacher Course is already exists.");
                }
                else
                {
                    teachersCourseAllocation.CreatedBy = Convert.ToInt32(Session["emp_id"]);
                    teachersCourseAllocation.CreatedOn = DateTime.Now;
                    db.TeachersCourseAllocations.Add(teachersCourseAllocation);
                    try
                    {
                        db.SaveChanges();
                        ViewBag.MessageType = "success";
                        ViewBag.Message     = "Data has been saved successfully.";
                    }
                    catch (DbUpdateException ex)
                    {
                        ViewBag.MessageType = "error";
                        ViewBag.Message     = ex.Message;
                        ModelState.AddModelError(string.Empty, ex.Message);
                    }
                }
            }
            catch (DbEntityValidationException ex)
            {
                foreach (DbEntityValidationResult validationResult in ex.EntityValidationErrors)
                {
                    string entityName = validationResult.Entry.Entity.GetType().Name;
                    foreach (DbValidationError error in validationResult.ValidationErrors)
                    {
                        ModelState.AddModelError(string.Empty, error.ErrorMessage);
                        count++;
                        ErrorMessage += count + "-" + string.Concat(error.PropertyName, " is required.") + "<br />";
                    }
                }
                ViewBag.MessageType = "error";
                ViewBag.Message     = ErrorMessage;
            }
            model.TeachersCourseAllocations        = db.TeachersCourseAllocations.OrderByDescending(t => t.TCourseAllocationID).ToList();
            model.SelectedTeachersCourseAllocation = null;
            model.DisplayMode       = "WriteOnly";
            ViewBag.IsActive        = new SelectList(db.Options, "OptionDesc", "OptionDesc", teachersCourseAllocation.IsActive);
            ViewBag.ProgramCourseID = new SelectList(db.GetBatchProgramNameConcat("", 1), "ID", "Name", teachersCourseAllocation.ProgramCourseID);
            ViewBag.TeacherID       = new SelectList(db.Teachers, "TeacherID", "TeacherName", teachersCourseAllocation.TeacherID);
            return(View("Index", model));
        }
예제 #2
0
 public ActionResult Edit(TeachersCourseAllocation teachersCourseAllocation)
 {
     try
     {
         db.Entry(teachersCourseAllocation).State = EntityState.Modified;
         teachersCourseAllocation.ModifiedBy      = Convert.ToInt32(Session["emp_id"]);
         teachersCourseAllocation.ModifiedOn      = DateTime.Now;
         try
         {
             db.SaveChanges();
             ViewBag.MessageType = "success";
             ViewBag.Message     = "Data has been saved successfully.";
         }
         catch (DbUpdateException ex)
         {
             ViewBag.MessageType = "error";
             ViewBag.Message     = ex.Message;
             ModelState.AddModelError(string.Empty, ex.Message);
         }
     }
     catch (DbEntityValidationException ex)
     {
         string ErrorMessage = "";
         int    count        = 0;
         foreach (DbEntityValidationResult validationResult in ex.EntityValidationErrors)
         {
             string entityName = validationResult.Entry.Entity.GetType().Name;
             foreach (DbValidationError error in validationResult.ValidationErrors)
             {
                 ModelState.AddModelError(string.Empty, error.ErrorMessage);
                 count++;
                 ErrorMessage += string.Concat(count, "-", error.ErrorMessage, "\n");
             }
         }
         ViewBag.MessageType = "error";
         ViewBag.Message     = ErrorMessage;
     }
     model.TeachersCourseAllocations        = db.TeachersCourseAllocations.OrderByDescending(t => t.TCourseAllocationID).ToList();
     model.SelectedTeachersCourseAllocation = null;
     model.DisplayMode       = "WriteOnly";
     ViewBag.IsActive        = new SelectList(db.Options, "OptionDesc", "OptionDesc", teachersCourseAllocation.IsActive);
     ViewBag.ProgramCourseID = new SelectList(db.GetBatchProgramNameConcat("", 1), "ID", "Name", teachersCourseAllocation.ProgramCourseID);
     ViewBag.TeacherID       = new SelectList(db.Teachers, "TeacherID", "TeacherName", teachersCourseAllocation.TeacherID);
     return(View("Index", model));
 }
예제 #3
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TeachersCourseAllocation teachersCourseAllocation = db.TeachersCourseAllocations.Find(id);

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

            model.TeachersCourseAllocations        = db.TeachersCourseAllocations.OrderByDescending(t => t.TCourseAllocationID).ToList();
            model.SelectedTeachersCourseAllocation = teachersCourseAllocation;
            model.DisplayMode   = "Delete";
            ViewBag.MessageType = "";
            ViewBag.Message     = "";
            return(View("Index", model));
        }
예제 #4
0
 public ActionResult DeleteConfirmed(int id)
 {
     try
     {
         TeachersCourseAllocation teachersCourseAllocation = db.TeachersCourseAllocations.Find(id);
         db.TeachersCourseAllocations.Remove(teachersCourseAllocation);
         db.SaveChanges();
         ViewBag.MessageType = "success";
         ViewBag.Message     = "Record has been removed successfully.";
     }
     catch (DbUpdateException ex)
     {
         ViewBag.MessageType = "error";
         ViewBag.Message     = ex.Message;
         ModelState.AddModelError(string.Empty, ex.Message);
     }
     model.TeachersCourseAllocations        = db.TeachersCourseAllocations.OrderByDescending(t => t.TCourseAllocationID).ToList();
     model.SelectedTeachersCourseAllocation = null;
     model.DisplayMode       = "WriteOnly";
     ViewBag.IsActive        = new SelectList(db.Options, "OptionDesc", "OptionDesc");
     ViewBag.ProgramCourseID = new SelectList(db.GetBatchProgramNameConcat("", 1), "ID", "Name");
     ViewBag.TeacherID       = new SelectList(db.Teachers, "TeacherID", "TeacherName");
     return(View("Index", model));
 }
예제 #5
0
        public ActionResult Update(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            TeachersCourseAllocation teachersCourseAllocation = db.TeachersCourseAllocations.Find(id);

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

            model.TeachersCourseAllocations        = db.TeachersCourseAllocations.OrderByDescending(t => t.TCourseAllocationID).ToList();
            model.SelectedTeachersCourseAllocation = teachersCourseAllocation;
            model.DisplayMode       = "ReadWrite";
            ViewBag.IsActive        = new SelectList(db.Options, "OptionDesc", "OptionDesc", teachersCourseAllocation.IsActive);
            ViewBag.ProgramCourseID = new SelectList(db.GetBatchProgramNameConcat("", 1), "ID", "Name", teachersCourseAllocation.ProgramCourseID);
            ViewBag.TeacherID       = new SelectList(db.Teachers, "TeacherID", "TeacherName", teachersCourseAllocation.TeacherID);
            ViewBag.MessageType     = "";
            ViewBag.Message         = "";
            return(View("Index", model));
        }