public ActionResult Faculty(SVM.Faculty model, int page = 1, char action = '0', int row = -1, int id_faculty = -1)
        {
            switch (action)
            {
                case 'a':
                    ModelState.Clear();

                    ViewBag.action = action;
                    ViewBag.row = row;

                    model = new SVM.Faculty();
                    break;

                case 's':
                    if (ModelState.IsValid)
                    {
                        if (DB.Faculty.Count(f => f.name == model.name || f.abbreviation == model.abbreviation) > 0)
                        {
                            ViewBag.action = 'a';
                            ViewBag.row = row;

                            ModelState.AddModelError("-2", Localizator.Localizate("Faculty_duplicate_name_or_abbreviation_error", CurrentLangCode));
                        }
                        else
                        {
                            ViewBag.action = '0';
                            ViewBag.row = -1;

                            try
                            {
                                DB.Faculty.Add(model);
                                DB.SaveChanges();
                            }
                            catch (Exception ex)
                            {
                                ModelState.AddModelError("-3", Localizator.Localizate("Faculty_add_error", CurrentLangCode));
                                if (HttpContext.IsDebuggingEnabled)
                                    ModelState.AddModelError("-3", ex.GetBaseException().Message);
                            }
                        }
                    }
                    else
                    {
                        ViewBag.action = 'a';
                        ViewBag.row = row;
                    }
                    break;

                case 'e':
                    ModelState.Clear();

                    ViewBag.action = action;
                    ViewBag.row = row;

                    model = DB.Faculty.Find(id_faculty);
                    break;

                case 'u':
                    if (ModelState.IsValid)
                    {
                        if (DB.Faculty.Count(f => (f.name == model.name || f.abbreviation == model.abbreviation) && f.id_faculty != model.id_faculty) > 0)
                        {
                            ViewBag.action = 'e';
                            ViewBag.row = row;

                            ModelState.AddModelError("-2", Localizator.Localizate("Faculty_duplicate_name_or_abbreviation_error", CurrentLangCode));
                        }
                        else
                        {
                            ViewBag.action = '0';
                            ViewBag.row = -1;

                            try
                            {
                                DB.Faculty.Find(id_faculty).name = model.name;
                                DB.Faculty.Find(id_faculty).abbreviation = model.abbreviation;
                                DB.SaveChanges();
                            }
                            catch (Exception ex)
                            {
                                ModelState.AddModelError("-3", Localizator.Localizate("Faculty_edit_error", CurrentLangCode));
                                if (HttpContext.IsDebuggingEnabled)
                                    ModelState.AddModelError("-3", ex.GetBaseException().Message);
                            }
                        }
                    }
                    else
                    {
                        ViewBag.action = 'e';
                        ViewBag.row = row;
                    }
                    break;

                case 'r':
                    ModelState.Clear();
                    model = DB.Faculty.Find(id_faculty);
                    if (DB.Faculty.Count(f => f.name == model.name || f.abbreviation == model.abbreviation) > 0)
                    {
                        try
                        {
                            DB.Faculty.Remove(DB.Faculty.Find(id_faculty));
                            DB.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            ModelState.AddModelError("-4", Localizator.Localizate("Faculty_delete_error", CurrentLangCode));
                            if (HttpContext.IsDebuggingEnabled)
                                ModelState.AddModelError("-4", ex.GetBaseException().Message);
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("-5", Localizator.Localizate("Faculty_existance_error", CurrentLangCode));
                    }
                    break;

                default:
                    ModelState.Clear();

                    ViewBag.action = '0';
                    ViewBag.row = -1;
                    break;
            }

            try
            {
                IQueryable<SVM.Faculty> Ifaculies;

                int elements_on_page = Int32.Parse(ConfigurationManager.AppSettings["ElementsOnPage"]);
                if (DB.Faculty.Count() <= elements_on_page)
                {
                    ViewBag.pages = 1;
                    Ifaculies = DB.Faculty;
                }
                else
                {
                    int pages = (DB.Faculty.Count() / elements_on_page) + 1;

                    ViewBag.elements_on_page = elements_on_page;
                    ViewBag.page = page;
                    ViewBag.pages = pages;

                    if (page == 1)
                        Ifaculies = DB.Faculty.Take(elements_on_page);
                    else
                    {
                        if (page == pages)
                            Ifaculies = DB.Faculty.OrderBy(f => f.id_faculty).Skip(elements_on_page * (page - 1));
                        else
                            Ifaculies = DB.Faculty.OrderBy(f => f.id_faculty).Skip(elements_on_page * (page - 1)).Take(elements_on_page);
                    }
                }

                ViewBag.faculties = Ifaculies.ToList();
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("-1", Localizator.Localizate("Faculty_view_error", CurrentLangCode));
                if (HttpContext.IsDebuggingEnabled)
                    ModelState.AddModelError("-1", ex.GetBaseException().Message);
            }

            return View(model);
        }
            public void FacultyTest_ValidDataEmptyConstructor_ShouldIsNotNull()
            {
                //arrange

                //act
                var result = new SVM.Faculty();
                //assert
                Assert.IsNotNull(result);
            }
 public void FacultyTest_ValidData_ShouldIsInstanceOfType()
 {
     //arrange
     string name = "Sociology";
     string abbr = "S";
     //act
     object result = new SVM.Faculty(name, abbr);
     //assert
     Assert.IsInstanceOfType(result, typeof(SVM.Faculty));
 }
 public void FacultyTest_InvalidDataNullIdFaculty_ShouldIsNotNull()
 {
     //arrange
     SVM.Faculty faculty = new SVM.Faculty();
     //act
     var result = faculty.id_faculty;
     //assert
     Assert.IsNotNull(result);
 }