Exemplo n.º 1
0
 public bool Equals(SecurityMarks other)
 {
     if (ReferenceEquals(other, null))
     {
         return(false);
     }
     if (ReferenceEquals(other, this))
     {
         return(true);
     }
     if (Name != other.Name)
     {
         return(false);
     }
     if (!Marks.Equals(other.Marks))
     {
         return(false);
     }
     if (CanonicalName != other.CanonicalName)
     {
         return(false);
     }
     return(Equals(_unknownFields, other._unknownFields));
 }
Exemplo n.º 2
0
        public override bool Equals(object obj)
        {
            var a = (Student)obj;

            return(Name.Equals(a.Name) && Group.Equals(a.Group) && Marks.Equals(a.Marks));
        }
        public ActionResult UploadMark(string faculty, string session, string course_code, HttpPostedFileBase file, string msg)
        {
            if (!HasSession())
            {
                return(RedirectToAction("Index", "Home"));
            }
            Teacher teacher = HttpContext.Session[Variables.TeacherSession] as Teacher;

            if (faculty != null && session != null && course_code != null && file != null)
            {
                course_code = course_code.Trim().Replace(" ", "_").ToUpper();
                string fileName = "", targetFileName = course_code + "_" + session.Replace("-", "_");

                if ((file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName))
                {
                    //string fileContentType = Path.GetExtension(file.FileName).ToLower();
                    fileName = Path.GetFileName(file.FileName);

                    if (fileName.ToLower().Contains(".xls") || fileName.ToLower().Contains(".xlsx"))
                    {
                        List <Marks> marks = new ExcelReader().readMarksFromExcel(file);

                        if (marks != null)
                        {
                            string ValidityCheckRes = new Marks().IsValid(marks);
                            if (ValidityCheckRes.Equals(Messasges.Valid))
                            {
                                string InsertionRes = new Marks().InserMarkList(marks, faculty, course_code);
                                ViewBag.Marks   = marks;
                                ViewBag.Course  = course_code;
                                ViewBag.Faculty = faculty;

                                if (!InsertionRes.Contains(Messasges.InsertionFailed))
                                {
                                    ViewBag.Message = Messasges.DataUploadedSuccessfully;
                                    CourseStatus.AddCourseStatus(course_code, session, false);

                                    try
                                    {
                                        //targetFileName += "_" + DateTime.Now.ToString().Replace("/", "_").Replace(" ", "_").Replace(":", "_") + ".xlsx";
                                        targetFileName += ".xlsx";
                                        string path = Path.Combine(Server.MapPath("~/App_Data/Marks/"), targetFileName);
                                        file.SaveAs(path);
                                        ViewBag.FileInfo = targetFileName + " uploaded successfully!";

                                        TeacherActivity activity = new TeacherActivity();
                                        activity.Name        = teacher.Name;
                                        activity.Designation = teacher.Department;
                                        activity.CourseCode  = course_code;
                                        activity.Session     = session;
                                        activity.UserId      = teacher.TeacherID.ToString();
                                        activity.Time        = DateTime.Now.ToString();
                                        msg = "Marks uploaded for: " + course_code + ", " + session + ".\n" + msg;
                                        activity.Message  = msg;
                                        activity.Content  = InsertionRes;
                                        activity.FilePath = path;

                                        db.TeacherActivity.Add(activity);
                                        db.SaveChanges();

                                        TeacherActivity act = db.TeacherActivity.Where(p => p.Time == activity.Time).FirstOrDefault();
                                        ViewBag.ActivityId = act.id;
                                    }
                                    catch (Exception ex)
                                    {
                                        ViewBag.Error = "ERROR:" + ex.Message.ToString();
                                    }
                                }
                                else
                                {
                                    ViewBag.Error = Messasges.DataUploadFailed;
                                }
                            }
                            else
                            {
                                ViewBag.Error = ValidityCheckRes;
                            }
                        }
                        else
                        {
                            ViewBag.Error = Messasges.InvalidExcelData;
                        }
                    }
                    else
                    {
                        //format not supported
                        ViewBag.Error = Messasges.InvalidExcelFileFormate;
                    }
                }
            }
            else
            {
                ViewBag.Error = Messasges.RequiredFiledsMissing;
            }

            ViewBag.courses     = db.Courses.Where(dp => dp.CourseTeacherID == teacher.TeacherID).ToList();
            ViewBag.faculties   = db.Faculty.ToList();
            ViewBag.all_session = db.AllSession.ToList();

            return(View());
        }
Exemplo n.º 4
0
        public ActionResult ChangeExcelHistory(int id, HttpPostedFileBase file)
        {
            if (!HasSession())
            {
                return(RedirectToAction("Index", "Home"));
            }

            TeacherActivity activity = db.TeacherActivity.Find(id);

            string[] Ids = activity.Content.Split(',');
            //string content = Ids[0] + "," + Ids[1];

            if ((file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName))
            {
                //string fileContentType = Path.GetExtension(file.FileName).ToLower();
                string fileName = Path.GetFileName(file.FileName);
                if (fileName.ToLower().Contains(".xls") || fileName.ToLower().Contains(".xlsx"))
                {
                    //delete old marks
                    Boolean isDeleted = new Marks().DeleteEntries(Ids);

                    //insert new marks
                    List <Marks> marks = new ExcelReader().readMarksFromExcel(file);
                    if (marks != null)
                    {
                        string ValidityCheckRes = new Marks().IsValid(marks);
                        if (ValidityCheckRes.Equals(Messasges.Valid))
                        {
                            string res = new Marks().InserMarkList(marks, Ids[0], Ids[1]);

                            if (res.Contains(Messasges.InsertionFailed))
                            {
                                ViewBag.Error = Messasges.DataUpdateFailed;
                            }
                            else
                            {
                                ViewBag.Message = Messasges.DataUpdatedSuccessfully;
                            }

                            try
                            {
                                file.SaveAs(activity.FilePath);

                                TeacherActivity newActivity = new TeacherActivity();
                                newActivity.Name        = activity.Name;
                                newActivity.Designation = activity.Designation;
                                newActivity.CourseCode  = activity.CourseCode;
                                newActivity.UserId      = activity.UserId;
                                newActivity.Time        = DateTime.Now.ToString();
                                newActivity.Message     = activity.Message.Replace("uploaded", "changed");
                                newActivity.Content     = res;
                                newActivity.FilePath    = activity.FilePath;

                                db.TeacherActivity.Add(newActivity);
                                activity.FilePath = null;
                                db.SaveChanges();
                            }
                            catch (Exception ex)
                            {
                                ViewBag.FileInfo = "ERROR:" + ex.Message.ToString();
                            }

                            return(RedirectToAction("Index", "History"));
                        }
                        else
                        {
                            ViewBag.Error = ValidityCheckRes;
                        }
                    }
                    else
                    {
                        ViewBag.Error = Messasges.InvalidExcelData;
                    }
                }
                else
                {
                    //format not supported
                    ViewBag.Error = Messasges.InvalidExcelFileFormate;
                }
            }
            else
            {
                ViewBag.Error = "No input data!";
            }

            ViewBag.Id = id;

            return(View());
        }