public ActionResult Shop() { team4zooEntities DB = new team4zooEntities(); List <Shop> shoplist = DB.Shops.ToList(); return(View(shoplist)); }
public ActionResult ViewInventory() { team4zooEntities db = new team4zooEntities(); List <Inventory> inventorylist = db.Inventory.ToList(); return(View(inventorylist)); }
public IEnumerable <string> ViewMyEmployees() { using (team4zooEntities db = new team4zooEntities()) { System.Guid MyEmployee_ID = (System.Guid)Session["Employee_ID"]; return(db.Employees.ToList().Where(x => (x.Supervisor_ID == MyEmployee_ID)).Select(y => y.username)); } }
public IEnumerable <Food_Supply> GetFoodTypes() { using (team4zooEntities db = new team4zooEntities()) { //yield return db.Food_Supply.ToList().Select(y => y.Food_type).FirstOrDefault(); return(db.Database.SqlQuery <Food_Supply>("select * from zoo.Food_Supply").ToList()); } }
public IEnumerable <Animal> ViewMyAnimals() { using (team4zooEntities db = new team4zooEntities()) { System.Guid Employee_ID = (System.Guid)Session["Employee_ID"]; return(db.Animals.ToList().Where(x => (x.Assignee1_ID == Employee_ID || x.Assignee2_ID == Employee_ID || x.Assignee3_ID == Employee_ID))); } }
public IEnumerable <Animal> ViewMyAnimals() { using (team4zooEntities db = new team4zooEntities()) { System.Guid Employee_ID = (System.Guid)Session["Employee_ID"]; return(db.Animals.ToList()); } }
public ActionResult MyAnimals() { using (team4zooEntities DB = new team4zooEntities()) { List <Animal> AnimalList = DB.Animals.ToList(); return(View(AnimalList)); } }
public ActionResult ViewAttractions() { team4zooEntities db = new team4zooEntities(); List <Attraction> attractionlist = db.Attractions.ToList(); List <Attraction> SortedAttractions = attractionlist.OrderBy(x => x.start_date).ToList(); return(View(SortedAttractions)); }
public ActionResult Item() { using (team4zooEntities DB = new team4zooEntities()) { List <Inventory> itemlist = DB.Inventory.ToList(); return(View(itemlist)); } }
public ActionResult Dept() { using (team4zooEntities DB = new team4zooEntities()) { List <Department> deptlist = DB.Departments.ToList(); return(View(deptlist)); } }
public ActionResult editDept(string id) { using (team4zooEntities DB = new team4zooEntities()) { Guid ID = new Guid(id); Department department = DB.Departments.Single(Department => Department.Department_ID == ID); return(View(department)); } }
public ActionResult editEmp(string id) { using (team4zooEntities DB = new team4zooEntities()) { Guid ID = new Guid(id); var tmpEmp = DB.Employees.Single(e => e.Employee_ID == ID); return(View(tmpEmp)); } }
public ActionResult editItem(string id) { using (team4zooEntities DB = new team4zooEntities()) { Guid ID = new Guid(id); Inventory item = DB.Inventory.Single(Inventory => Inventory.Item_ID == ID); return(View(item)); } }
public IEnumerable <Attraction> getNames(IEnumerable <Attraction> MyAttr) { using (team4zooEntities db = new team4zooEntities()) { foreach (var item in MyAttr) { string Fname = db.Employees.Where(x => x.Employee_ID == item.manager_ID).Select(y => y.f_name).FirstOrDefault(); string LName = db.Employees.Where(x => x.Employee_ID == item.manager_ID).Select(y => y.l_name).FirstOrDefault(); item.manager_name = Fname + " " + LName; } return(MyAttr); } }
public ActionResult MedicationEntery(Animal Model) { using (team4zooEntities db = new team4zooEntities()) { try { Animal_Medication_Care NewEntry = new Animal_Medication_Care(); NewEntry.Animal_ID = db.Animals.Where(x => x.animal_name == Model.animal_name).Select(y => y.Animal_ID).FirstOrDefault(); NewEntry.medication = Model.medication; NewEntry.dose = Model.dose; NewEntry.description = Model.description; NewEntry.Employee_ID = (System.Guid)Session["Employee_ID"]; NewEntry.date = DateTime.Today; NewEntry.time = DateTime.Now.Subtract(DateTime.Today); NewEntry.vet = Model.vet; if (Model.animal_name == null || Model.medication == null || Model.dose == null || Model.vet == null || Model.description == null) { IEnumerable <Animal> MyAnimals = ViewMyAnimals(); IEnumerable <Food_Supply> Food = GetFoodTypes(); List <string> ErrorMsg = new List <string>(); ErrorMsg.Add("Fill All the Fields!"); var tuple = new Tuple <IEnumerable <Animal>, IEnumerable <Food_Supply>, IEnumerable <string> >(MyAnimals, Food, ErrorMsg); return(View("~/Views/FeedCare/Index.cshtml", tuple)); } else { //add new food entry to database db.Animal_Medication_Care.Add(NewEntry); //save changes to database db.SaveChanges(); return(RedirectToAction("Index", "FeedCare")); } } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } } }
public bool CheckExistingName(string Name) { using (team4zooEntities db = new team4zooEntities()) { var User = db.Animals.Where(x => x.animal_name == Name).FirstOrDefault(); //check if user exists in the database already if (User == null) //not in db { return(false); } else { return(true); //return true if user is in db } } }
//checks if username already exists, if it does, you may not change your username public bool CheckExistingUser(UserProfile userModel) { using (team4zooEntities db = new team4zooEntities()) { var User = db.Credentials.Where(x => x.username == userModel.newUsername).FirstOrDefault(); //check if user exists in the database already if (User == null) //not in db { return(false); } else { return(true); //return true if user is in db } } }
public ActionResult Contact(Employee Model) { using (team4zooEntities db = new team4zooEntities()) { var Phone = db.Employees.Where(x => x.f_name == Model.f_name && x.l_name == Model.l_name).Select(y => y.phone_num).FirstOrDefault(); var Email = db.Employees.Where(x => x.f_name == Model.f_name && x.l_name == Model.l_name).Select(y => y.email).FirstOrDefault(); String contactInfo = " Phone: " + Phone + " " + ", " + " Email: " + Email; if (Phone != null && Email != null) { ViewBag.Message = contactInfo; } else { ViewBag.Message = "No one by that name was found"; } return(View()); } }
public ActionResult EditPhone(UserProfile userModel) { using (team4zooEntities db = new team4zooEntities()) { Regex reg = new Regex(@"^[2-9]\d{2}-\d{3}-\d{4}$"); System.Guid Employee_ID = (System.Guid)Session["Employee_ID"]; string newPhone = userModel.newPhone; if (!reg.IsMatch(newPhone)) { userModel.PhoneErrorMessage = "Invalid Input"; return(View("Index", userModel)); } else { db.Database.ExecuteSqlCommand("update zoo.Employee set phone_num = '" + newPhone + "' where Employee_ID = '" + Employee_ID + "'"); Session.Abandon(); return(RedirectToAction("Index", "Home")); } } }
public ActionResult Inventory(Inventory Model) { using (team4zooEntities db = new team4zooEntities()) { var Price = db.Inventory.Where(x => x.item_name == Model.item_name).Select(y => y.price).FirstOrDefault(); var InStock = db.Inventory.Where(x => x.item_name == Model.item_name).Select(y => y.ordered_quantity).FirstOrDefault(); var ItemName = db.Inventory.Where(x => x.item_name == Model.item_name).Select(y => y.item_name).FirstOrDefault(); String ItemInfo = ItemName + " Price: " + Price + " " + ", " + " In Stock: " + InStock; if (ItemName != null) { ViewBag.Message = ItemInfo; } else { ViewBag.Message = "No Item Found"; } return(View()); } }
public ActionResult ViewMedicationReport(Animal model, DateTime?from, DateTime?to) { using (team4zooEntities db = new team4zooEntities()) { System.Guid Animal_ID = db.Animals.Where(x => x.animal_name == model.animal_name).Select(y => y.Animal_ID).FirstOrDefault(); if (!from.HasValue || !to.HasValue || model.animal_name == null) { List <string> ErrorMsg = new List <string>(); ErrorMsg.Add("Fill All the Fields!"); IEnumerable <Animal> MyAnimals = ViewMyAnimals(); var tuple = new Tuple <IEnumerable <Animal>, IEnumerable <string> >(MyAnimals, ErrorMsg); return(View("~/Views/CareGiverReport/Index.cshtml", tuple)); } else { IEnumerable <Animal_Medication_Care> MedicationReport = db.Animal_Medication_Care.Where(x => x.Animal_ID == Animal_ID && (x.date >= from || x.date <= to)).ToList(); var tuple = new Tuple <IEnumerable <Animal_Medication_Care> >(MedicationReport); return(View("~/Views/CareGiverReport/MedicationReport.cshtml", tuple)); } } }
public ActionResult EditEmail(UserProfile userModel) { using (team4zooEntities db = new team4zooEntities()) { Regex reg = new Regex(@"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" + @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-0-9a-z]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$"); System.Guid Employee_ID = (System.Guid)Session["Employee_ID"]; string newEmail = userModel.newEmail; if (!reg.IsMatch(newEmail)) { userModel.EmailErrorMessage = "Invalid Input"; return(View("Index", userModel)); } else { db.Database.ExecuteSqlCommand("update zoo.Employee set email = '" + newEmail + "' where Employee_ID = '" + Employee_ID + "'"); Session.Abandon(); return(RedirectToAction("Index", "Home")); } } }
//Revenue VS Expenditure Chart public ContentResult RevExpChart() { using (team4zooEntities DB = new team4zooEntities()) { //Chart View Data Model to store necessary data. List <DeptChartViewModel> dept = new List <DeptChartViewModel>(); //Get Department List var results = DB.Departments.ToList(); //Convert all necessary data to List. foreach (Department department in results) { DeptChartViewModel deptVM = new DeptChartViewModel(); //Assign Values //Check if underscore if (department.department_name.Contains('_')) { string tmpname = department.department_name.Replace("_", " "); deptVM.name = tmpname; } else { deptVM.name = department.department_name; } deptVM.expenditure = department.dep_expenditure; deptVM.revenue = department.dep_revenue; //Add to Chart Data dept.Add(deptVM); } //Return serialised Json return(Content(JsonConvert.SerializeObject(dept), "application/json")); } }
public ContentResult GetRoleList() { using (team4zooEntities DB = new team4zooEntities()) { List <RoleListModel> rolelist = new List <RoleListModel>(); //Get Role List var results = DB.Roles.ToList(); //Convert all necessary data to List. foreach (Role role in results) { RoleListModel roleVM = new RoleListModel(); //Assign Values //Check if underscore if (role.Job_Title.Contains('_')) { string tmpname = role.Job_Title.Replace("_", " "); roleVM.Job_Title = tmpname; } else { roleVM.Job_Title = role.Job_Title; } //Assign Role ID roleVM.Role_ID = role.Role_ID; //Add to Chart Data rolelist.Add(roleVM); } //Return serialised Json return(Content(JsonConvert.SerializeObject(rolelist), "application/json")); } }
public ActionResult Authorize(Credential userModel) { using (team4zooEntities db = new team4zooEntities()) { var userCredentials = db.Credentials.Where(x => x.username == userModel.username && x.password == userModel.password).FirstOrDefault(); if (userCredentials != null) //Correct username/password { var account_status = db.Employees.Where(x => x.Employee_ID == userCredentials.Employee_ID).Select(y => y.isActive).FirstOrDefault(); if (userCredentials.Employee_ID == null || Convert.ToInt32(account_status) == 0) { userModel.LoginErrorMessage = "The Account is deactivated"; return(View("Index", userModel)); } else { Session["Name"] = db.Employees.Where(x => x.Employee_ID == userCredentials.Employee_ID).Select(y => y.display_name).FirstOrDefault(); Session["username"] = userCredentials.username; System.Guid userRoleID = (System.Guid)db.Employees.Where(x => x.Employee_ID == userCredentials.Employee_ID).Select(y => y.Role_ID).FirstOrDefault(); Session["RoleName"] = db.Roles.Where(x => x.Role_ID == userRoleID).Select(y => y.Job_Title).FirstOrDefault(); Session["Employee_ID"] = userCredentials.Employee_ID; Session["RoleID"] = userRoleID; Session["FName"] = db.Employees.Where(x => x.Employee_ID == userCredentials.Employee_ID).Select(y => y.f_name).FirstOrDefault(); Session["LName"] = db.Employees.Where(x => x.Employee_ID == userCredentials.Employee_ID).Select(y => y.l_name).FirstOrDefault(); Session["Email"] = db.Employees.Where(x => x.Employee_ID == userCredentials.Employee_ID).Select(y => y.email).FirstOrDefault(); Session["Phone"] = db.Employees.Where(x => x.Employee_ID == userCredentials.Employee_ID).Select(y => y.phone_num).FirstOrDefault(); return(RedirectToAction("Index", "Home")); } } else { userModel.LoginErrorMessage = "Wrong Username/Password"; return(View("Index", userModel)); } } }
public ActionResult AddMember(Customer Model) { using (team4zooEntities db = new team4zooEntities()) { if (Model.f_name == null || Model.l_name == null || Model.phone_number == null) { ViewBag.Message = "Must Enter All Fields"; return(View()); } else { Customer NewEntry = new Customer(); NewEntry.Customer_ID = System.Guid.NewGuid(); NewEntry.f_name = Model.f_name; NewEntry.l_name = Model.l_name; NewEntry.phone_number = Model.phone_number; NewEntry.membership = true; db.Customers.Add(NewEntry); db.SaveChanges(); ViewBag.Message = "Member Added"; return(View()); } } }
public ActionResult AddAnimal(AddAnimal model, DateTime?dob) { using (team4zooEntities db = new team4zooEntities()) { try { Animal animal = new Animal(); animal.Animal_ID = Guid.NewGuid(); animal.animal_name = model.name; animal.dob = dob; animal.sex = model.sex; animal.weight = model.weight; animal.owner = model.owner; animal.isActive = true; animal.family = db.Family_Name.Where(x => x.family_title == model.familyN).Select(y => y.Family_ID).FirstOrDefault(); if (model.name == null || model.sex == null || model.weight.Equals(null) || model.weight.Equals(0.00) || !dob.HasValue || model.owner == null || model.ExhibitN == null) { AddAnimal newModel = modelMaker(); newModel.ErrorMessage1 = "Please, Fill all required fields."; return(View("~/Views/AddAnimal/Index.cshtml", newModel)); } else if (CheckExistingName(model.name)) { AddAnimal newModel = modelMaker(); newModel.ErrorMessage2 = "This Name Already Exists."; return(View("~/Views/AddAnimal/Index.cshtml", newModel)); } else { if (model.AttrN != null) { animal.Attraction_ID = db.Attractions.Where(x => x.attraction_name == model.AttrN).Select(y => y.Attraction_ID).FirstOrDefault(); } animal.Exhibit_ID = db.Exhibits.Where(x => x.exhibit_name == model.ExhibitN).Select(y => y.Exhibit_ID).FirstOrDefault(); animal.Assignee1_ID = db.Employees.Where(x => x.username == model.Assignee1).Select(y => y.Employee_ID).FirstOrDefault(); animal.Assignee2_ID = db.Employees.Where(x => x.username == model.Assignee2).Select(y => y.Employee_ID).FirstOrDefault(); animal.Assignee3_ID = db.Employees.Where(x => x.username == model.Assginee3).Select(y => y.Employee_ID).FirstOrDefault(); db.Animals.Add(animal); db.SaveChanges(); return(RedirectToAction("Index", "AddAnimal")); } } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } } }
public ActionResult editEmp(Employee employee) { using (team4zooEntities DB = new team4zooEntities()) { if (employee.f_name.Length <= 0) { ViewBag.Message = "Unable to Add, First Name cannot be blank!"; return(View()); } else if (employee.l_name.Length <= 0) { ViewBag.Message = "Unable to Add, Last Name cannot be blank!"; return(View()); } else if (employee.email.Length <= 0) { ViewBag.Message = "Unable to Add, Email cannot be blank!"; return(View()); } else if (employee.ssn.Length < 9) { ViewBag.Message = "Unable to Add, SSN must be 9 digits!"; return(View()); } else if (employee.phone_num.Length < 12) { ViewBag.Message = "Unable to Add, phone number format incorrect!"; return(View()); } else if (Convert.ToDouble(employee.hourly_wage) < 7.25) { ViewBag.Message = "Unable to Add, hourly wage cannot be lower than the minimum wage ($7.25)!"; return(View()); } /* * //Get Employee List * var results = DB.Employees.ToList(); * * * if(employee.Department_ID == null || employee.Department_ID == Guid.Empty) * { * foreach (Employee empTMP in results) * { * if(employee.Employee_ID == empTMP.Employee_ID) * { * employee.Department_ID = empTMP.Department_ID; * break; * } * } * } * * if (employee.Role_ID == null || employee.Role.Role_ID == Guid.Empty) * { * foreach(Employee empTMP in results) * { * if(employee.Role_ID == empTMP.Role_ID) * { * employee.Role_ID = empTMP.Role_ID; * break; * } * * } * } */ AdminController adminController = new AdminController(); employee.display_name = employee.f_name + " " + employee.l_name[0]; adminController.SaveEmployee(employee); ViewBag.Message = "Edit Successful"; return(RedirectToAction("searchEmp")); } }
/// <summary> /// SEARCH EMPLOYEE /// </summary> /// <returns></returns> public JsonResult GetEmployeeList() { using (team4zooEntities DB = new team4zooEntities()) { List <EmployeeViewModel> EmpList = new List <EmployeeViewModel>(); //Get Employee List var resultEMP = DB.Employees.ToList(); var resultDept = DB.Departments.ToList(); var resultRole = DB.Roles.ToList(); //Convert all necessary data to List. foreach (Employee employee in resultEMP) { EmployeeViewModel empVM = new EmployeeViewModel(); //Assign Values empVM.f_name = employee.f_name; empVM.mid_init = employee.mid_init; empVM.l_name = employee.l_name; empVM.email = employee.email; empVM.sex = employee.sex.ToUpper(); empVM.dob = employee.dob.ToString("yyyy/MM/dd"); empVM.ssn = employee.ssn; empVM.hourly_wage = employee.hourly_wage; empVM.hire_date = employee.hire_date.ToString("yyyy/MM/dd"); empVM.sick_days = employee.sick_days; empVM.phone_num = employee.phone_num; empVM.Employee_ID = employee.Employee_ID; empVM.Department_ID = employee.Department_ID; empVM.Role_ID = employee.Role_ID; //If Department ID Exists, get Department Name if (empVM.Department_ID != null) { foreach (Department department in resultDept) { if (empVM.Department_ID == department.Department_ID) { empVM.department_name = department.department_name; //Check if underscore if (empVM.department_name.Contains('_')) { string tmpname = empVM.department_name.Replace("_", " "); empVM.department_name = tmpname; } break; } } } else { empVM.department_name = "Unassigned"; } //If Role ID Exists, get Job Title if (empVM.Role_ID != null) { foreach (Role role in resultRole) { if (empVM.Role_ID == role.Role_ID) { empVM.Job_Title = role.Job_Title; //Check if underscore if (empVM.Job_Title.Contains('_')) { string tmpname = empVM.Job_Title.Replace("_", " "); empVM.Job_Title = tmpname; } break; } } } else { empVM.Job_Title = "Unassigned"; } //Set Active to readable if (employee.isActive == true) { empVM.isActive = "Active"; } else { empVM.isActive = "Inactive"; } //Add to List EmpList.Add(empVM); } var empDat = EmpList.OrderBy(e => e.f_name).ToList(); //Return serialised Json //return Content(JsonConvert.SerializeObject(EmpList), "application/json"); return(Json(new { data = empDat }, JsonRequestBehavior.AllowGet)); } }
public ActionResult addEmp(FormCollection formCollection) { decimal tmpval; if (!Decimal.TryParse(formCollection["hourly_wage"], out tmpval)) { ViewBag.Message = "Unable to Add, invalid hourly wage!"; return(View()); } if (formCollection["f_name"].Length <= 0) { ViewBag.Message = "Unable to Add, First Name cannot be blank!"; return(View()); } else if (formCollection["l_name"].Length <= 0) { ViewBag.Message = "Unable to Add, Last Name cannot be blank!"; return(View()); } else if (formCollection["email"].Length <= 0) { ViewBag.Message = "Unable to Add, Email cannot be blank!"; return(View()); } else if (formCollection["ssn"].Length < 9) { ViewBag.Message = "Unable to Add, SSN must be 9 digits!"; return(View()); } else if (formCollection["phone_num"].Length < 12) { ViewBag.Message = "Unable to Add, phone number format incorrect!"; return(View()); } else if (Convert.ToDouble(formCollection["hourly_wage"]) < 7.25) { ViewBag.Message = "Unable to Add, hourly wage cannot be lower than the minimum wage ($7.25)!"; return(View()); } DateTime tmpD = new DateTime(); if (!DateTime.TryParse(formCollection["dob"], out tmpD)) { ViewBag.Message = "Unable to Add, Date of Birth not selected"; return(View()); } else if (!DateTime.TryParse(formCollection["hire_date"], out tmpD)) { ViewBag.Message = "Unable to Add, Hire Date not selected"; return(View()); } //Check Input if (ModelState.IsValid) { //Assign Values Employee employee = new Employee(); employee.f_name = formCollection["f_name"]; if (formCollection["mid_init"].Length > 0) //If Middle initial exists, add { employee.mid_init = formCollection["mid_init"]; } else { employee.mid_init = null; } employee.l_name = formCollection["l_name"]; employee.email = formCollection["email"]; employee.sex = formCollection["sex"]; employee.dob = DateTime.Parse(formCollection["dob"]); employee.ssn = formCollection["ssn"]; employee.hire_date = DateTime.Parse(formCollection["hire_date"]); employee.phone_num = formCollection["phone_num"]; employee.hourly_wage = Convert.ToDecimal(formCollection["hourly_wage"]); //Checked Box condition check if (formCollection["isActive"] == "true,false") { employee.isActive = true; } else { employee.isActive = false; } if (formCollection["Department_ID"] != "null") { Guid DeptID = new Guid(formCollection["Department_ID"]); employee.Department_ID = DeptID; } else { employee.Department_ID = null; } if (formCollection["Role_ID"] != "null") { Guid roleID = new Guid(formCollection["Role_ID"]); employee.Role_ID = roleID; } else { employee.Role_ID = null; } //Get Department's Supervisor ID if (formCollection["Department_ID"] != "null") { using (team4zooEntities DB = new team4zooEntities()) { Guid id = new Guid(formCollection["Department_ID"]); Department department = DB.Departments.Single(Department => Department.Department_ID == id); employee.Supervisor_ID = department.Supervisor_ID; } } else { employee.Supervisor_ID = null; } //Set DisplayName employee.display_name = employee.f_name + " " + employee.l_name[0]; //INSERT ADD FUNCTION HERE AdminController adminController = new AdminController(); adminController.AddEmployee(employee); ViewBag.Message = "New Employee Added!"; return(RedirectToAction("Staff")); } else { ViewBag.Message = "Unable to Add, Error Input"; return(View()); } }