public ActionResult MaintainStock(Stock stock2, string button)
 {
     if (button == "Save")
     {
         try
         {
             Stock stock1 = db.Stocks.Find(stock2.Stock_ID);
             if (stock1 == null)
             {
                 return(HttpNotFound());
             }
             else
             {
                 db.Entry(stock1).CurrentValues.SetValues(stock2);
                 db.SaveChanges();
             }
         }
         catch (Exception e)
         {
             return(RedirectToAction("MaintainStock", "Stock"));
         }
     }
     else if (button == "Cancel")
     {
         return(RedirectToAction("Index", "Home"));
     }
     return(RedirectToAction("Index", "Home"));
 }
        public ActionResult Create([Bind(Include = "Vet_Appoint_Line_ID,Vet_ID,AppointmentDate,Description,Animal_ID,VetAppReasonsID")] Vet_Appointment_Master vet_Appointment_Master, DateTime?date)
        {
            if (ModelState.IsValid)
            {
                vet_Appointment_Master.AppointmentDate = date.Value;
                db.Vet_Appointment_Master.Add(vet_Appointment_Master);

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            List <Animal> animals  = db.Animals.ToList();
            List <Animal> animals2 = new List <Animal>();

            foreach (Animal item in animals)
            {
                if (item.Animal_Status_ID == 2)
                {
                    animals2.Add(item);
                }
            }
            ViewBag.Animal_ID       = new SelectList(animals2, "Animal_Name", "Animal_Name", vet_Appointment_Master.Animal_ID);
            ViewBag.Vet_ID          = new SelectList(db.Veterinarians, "Vet_ID", "Vet_Name", vet_Appointment_Master.Vet_ID);
            ViewBag.VetAppReasonsID = new SelectList(db.VetAppReasons, "VetAppReasonsID", "Reason", vet_Appointment_Master.VetAppReasonsID);
            return(View(vet_Appointment_Master));
        }
예제 #3
0
 public ActionResult AddDonor(Donor donor, string button)
 {
     if (button == "Save")
     {
         List <Donor> donors = new List <Donor>();
         donors = db.Donors.ToList();
         if (donors.Count != 0)
         {
             int count = 0;
             foreach (var item in donors)
             {
                 if (item.Donor_Name == donor.Donor_Name && item.Donor_Surname == donor.Donor_Surname && item.Donor_Email == donor.Donor_Email)
                 {
                     count++;
                     ViewBag.errorMessage = "There is a duplicate Donor Already";
                     return(View());
                 }
             }
             if (count == 0)
             {
                 db.Donors.Add(donor);
                 db.SaveChanges();
             }
         }
         db.Donors.Add(donor);
         db.SaveChanges();
         return(View());
     }
     else if (button == "Cancel")
     {
         return(RedirectToAction("Index", "Home"));
     }
     return(View());
 }
        public ActionResult Create([Bind(Include = "Vet_ID,Vet_Name,Vet_Emial,Vet_Tel,Vet_Address")] Veterinarian veterinarian)
        {
            if (ModelState.IsValid)
            {
                db.Veterinarians.Add(veterinarian);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(veterinarian));
        }
        public ActionResult Create([Bind(Include = "Event_Type_ID,Event_Type_Name")] Event_Type event_Type)
        {
            if (ModelState.IsValid)
            {
                db.Event_Type.Add(event_Type);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(event_Type));
        }
        public ActionResult Create([Bind(Include = "Kennel_ID,Kennel_Name,Kennel_Number,Kennel_Capacity")] Kennel kennel)
        {
            if (ModelState.IsValid)
            {
                db.Kennels.Add(kennel);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(kennel));
        }
        public ActionResult Create([Bind(Include = "Contract_ID,Electronic_Contract,Adopter_ID")] Adopter_Contract adopter_Contract)
        {
            if (ModelState.IsValid)
            {
                db.Adopter_Contract.Add(adopter_Contract);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Adopter_ID = new SelectList(db.Adopters, "Adopter_ID", "Adopter_Name", adopter_Contract.Adopter_ID);
            return(View(adopter_Contract));
        }
예제 #8
0
        public ActionResult Create([Bind(Include = "Vol_WorkType_ID,Vol_WorkType_Name,Vol_WorkType_Description")] Volunteer_Work_Type volunteer_Work_Type)
        {
            if (ModelState.IsValid)
            {
                db.Volunteer_Work_Type.Add(volunteer_Work_Type);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(volunteer_Work_Type));
        }
        public ActionResult Create([Bind(Include = "Vol_ID,Vol_Name,Vol_Surname,Vol_Email,Vol_ContactNumber,Vol_Address,Vol_Emergency_ContactName,Vol_Emergency_ContactNumber,Title_ID")] Volunteer volunteer)
        {
            if (ModelState.IsValid)
            {
                db.Volunteers.Add(volunteer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Title_ID = new SelectList(db.Titles, "Title_ID", "Title_Description", volunteer.Title_ID);
            return(View(volunteer));
        }
        public ActionResult Create([Bind(Include = "Vet_Appointment_ID,Vet_ID")] Vet_Appointment vet_Appointment)
        {
            if (ModelState.IsValid)
            {
                db.Vet_Appointment.Add(vet_Appointment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Vet_ID = new SelectList(db.Veterinarians, "Vet_ID", "Vet_Name", vet_Appointment.Vet_ID);
            return(View(vet_Appointment));
        }
예제 #11
0
        public ActionResult Create([Bind(Include = "Relative_ID,Relative_Name,Relative_Surname,Relative_Email,Relative_Address,Relative_PostalAddress,Relative_Home_Tel,Relative_Work_Tel,Relative_Cell,Relationship,Adopter_ID")] Adopter_Relative adopter_Relative)
        {
            if (ModelState.IsValid)
            {
                db.Adopter_Relative.Add(adopter_Relative);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Adopter_ID = new SelectList(db.Adopters, "Adopter_ID", "Adopter_Name", adopter_Relative.Adopter_ID);
            return(View(adopter_Relative));
        }
        public ActionResult Create([Bind(Include = "Vol_Hours_ID,Vol_workDate,Vol_Start_Time,Vol_End_Time,Vol_ID,Vol_WorkType_ID")] Volunteer_Hours volunteer_Hours)
        {
            if (ModelState.IsValid)
            {
                db.Volunteer_Hours.Add(volunteer_Hours);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Vol_ID          = new SelectList(db.Volunteers, "Vol_ID", "Vol_Name", volunteer_Hours.Vol_ID);
            ViewBag.Vol_WorkType_ID = new SelectList(db.Volunteer_Work_Type, "Vol_WorkType_ID", "Vol_WorkType_Name", volunteer_Hours.Vol_WorkType_ID);
            return(View(volunteer_Hours));
        }
        public ActionResult Create([Bind(Include = "Treat_ID,Animal_ID,Treat_StartDate,Treat_EndDate,Treat_Quantity,Treat_Regularity,Treat_Name,Treat_cost,Comment,Id")] Animal_Treatment animal_Treatment)
        {
            if (ModelState.IsValid)
            {
                db.Animal_Treatment.Add(animal_Treatment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Animal_ID = new SelectList(db.Animals, "Animal_ID", "Animal_Image", animal_Treatment.Animal_ID);
            ViewBag.Id        = new SelectList(db.Mecidal_Card, "Id", "Diagnosis_Details", animal_Treatment.Id);
            return(View(animal_Treatment));
        }
예제 #14
0
        public ActionResult Create([Bind(Include = "Adopter_ID,Adopter_Name,Adopter_Surname,Adopter_Email,Title_ID,Adopter_Address,Adopter_PostalAddress,Adopter_HomeNumber,Adopter_WorkNumber,Adopter_CellNumber,Adopter_CarRegistartion_Number,Adopter_Employer,Adopter_Status_ID,Amount_of_Family_Memebers,No_of_Children,Age_of_Children,Property_Securely_Closed,Properyty_Include_Pool,Pool_Secured,Animal_Shelter_Available,Sick_Animal,Sick_Animal_Diagnosis,Animal_Sleep_Location,Given_Animal_Away,HomeCheck_Suburb,Type_of_House,Adopted_Before,Complex_or_Flat,Animal_Allowed,Animal_Captivity,Animal_Vaccines_Updated")] Adopter adopter)
        {
            if (ModelState.IsValid)
            {
                db.Adopters.Add(adopter);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Title_ID          = new SelectList(db.Titles, "Title_ID", "Title_Description", adopter.Title_ID);
            ViewBag.Adopter_Status_ID = new SelectList(db.Adopter_Status, "Adopter_Status_ID", "Adopter_Status_Name", adopter.Adopter_Status_ID);
            return(View(adopter));
        }
        public ActionResult Create([Bind(Include = "Customer_Event_ID,Customer_Event_Name,Customer_Event_Surname,Customer_Event_Email,Number_of_tickects,TicketFee_Date,TicketFee_Total,Event_ID,Payment_Type_ID")] Customer_Event customer_Event)
        {
            if (ModelState.IsValid)
            {
                db.Customer_Event.Add(customer_Event);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Event_ID        = new SelectList(db.Event_, "Event_ID", "Event_Name", customer_Event.Event_ID);
            ViewBag.Payment_Type_ID = new SelectList(db.Payment_Type, "Payment_Type_ID", "Payment_Type_Name", customer_Event.Payment_Type_ID);
            return(View(customer_Event));
        }
예제 #16
0
        public ActionResult Create([Bind(Include = "Animal_Kennel_History_ID,Animal_ID,Kennel_ID")] Animal_Kennel_History animal_Kennel_History)
        {
            if (ModelState.IsValid)
            {
                db.Animal_Kennel_History.Add(animal_Kennel_History);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Animal_ID = new SelectList(db.Animals, "Animal_ID", "Animal_Name", animal_Kennel_History.Animal_ID);
            ViewBag.Kennel_ID = new SelectList(db.Kennels, "Kennel_ID", "Kennel_Name", animal_Kennel_History.Kennel_ID);
            return(View(animal_Kennel_History));
        }
예제 #17
0
        public JsonResult save(Vet_Appointment_Master vetApp)
        {
            bool     status = false;
            DateTime dateOrg;
            var      isValidDate = DateTime.TryParseExact(vetApp.VetDateString, "mm-dd-yyyy", null, System.Globalization.DateTimeStyles.None, out dateOrg);

            if (isValidDate)
            {
                vetApp.Appointment_Date = dateOrg;
            }

            var isValidModel = TryUpdateModel(vetApp);

            if (isValidModel)
            {
                using (Wollies_ShelterEntities dc = new Wollies_ShelterEntities())
                {
                    dc.Vet_Appointment_Master.Add(vetApp);
                    dc.SaveChanges();
                    status = true;
                }
            }
            return(new JsonResult {
                Data = new { status = status }
            });
        }
예제 #18
0
        public JsonResult SaveEvent(Event_Schedule e)
        {
            var status = false;

            using (Wollies_ShelterEntities dc = new Wollies_ShelterEntities())
            {
                if (e.EventID > 0)
                {
                    //Update the event
                    var v = dc.Event_Schedule.Where(a => a.EventID == e.EventID).FirstOrDefault();
                    if (v != null)
                    {
                        v.Subject     = e.Subject;
                        v.Start       = e.Start;
                        v.EventEnd    = e.EventEnd;
                        v.Description = e.Description;
                        v.IsFullDay   = e.IsFullDay;
                        v.ThemeColour = e.ThemeColour;
                    }
                }
                else //Add Event
                {
                    dc.Event_Schedule.Add(e);
                }

                dc.SaveChanges();
                status = true;
            }
            return(new JsonResult {
                Data = new { status = status }
            });
        }
        public ActionResult Checkout(string id)
        {
            DateTime datenow    = DateTime.Now;
            int      employeeid = Convert.ToInt32(id);

            List <TimeSheet> time = db.TimeSheets.Where(a => a.Emp_ID == employeeid).ToList();

            if (time.Count != 0)
            {
                List <string> Year = new List <string>();
                //here we look at each item to see if they checked in attribute is same as today date.
                foreach (var item in time)
                {
                    //for each item we need to look for the one that has no checkout value but has a checkin value that has same day
                    DateTime checkin    = (DateTime)item.Check_in;//here we get the date
                    string   storeddate = checkin.ToString("MM/dd/yyyy");
                    string   today      = datenow.ToString("MM/dd/yyyy");
                    //here we compare the current item date with today's date
                    if (storeddate == today)
                    {
                        //the date we get here is the one from checkout to see if teh re is a checkout date already
                        DateTime checkout = (DateTime)item.Check_out;
                        string   pastdate = checkout.ToString("MM/dd/yyyy");
                        if (pastdate == today)
                        {
                            Year.Add(today);
                        }
                    }
                }//I use this to see if the list is populated if is then the peron has already checked in today
                if (Year.Count == 0)
                {
                    TimeSheet timeSheet = new TimeSheet();
                    timeSheet.Emp_ID   = employeeid;
                    timeSheet.Check_in = datenow;
                    db.TimeSheets.Add(timeSheet);
                    db.SaveChanges();
                    return(RedirectToAction("Checkout"));
                }
                else
                {
                }
            }
            else
            {
            }
            return(View());
        }
예제 #20
0
        public ActionResult Create([Bind(Include = "Event_ID,Event_Name,Event_StartTime,Event_EndTime,Event_Guest_Number,Event_Ticket_Price,Event_Location,Event_Description,Event_Type_ID")] Event_ event_, DateTime?date, string time = "")
        {
            if (ModelState.IsValid)
            {
                int hour = Convert.ToInt32(time);

                DateTime dt = DateTime.Now;


                event_.Event_StartTime = date.Value;
                db.Event_.Add(event_);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Event_Type_ID = new SelectList(db.Event_Type, "Event_Type_ID", "Event_Type_Name", event_.Event_Type_ID);
            return(View(event_));
        }
예제 #21
0
        public ActionResult AddTemporaryAnimal(Animal animal, int[] Animal_Breed, Microchip micro, HttpPostedFileBase animalPicture)
        {
            try
            {
                if (animalPicture != null)
                {
                    //this is where we convert the contract to add to the database
                    byte[] bytes;
                    using (BinaryReader br = new BinaryReader(animalPicture.InputStream))
                    {
                        bytes = br.ReadBytes(animalPicture.ContentLength);
                    }
                    animal.Animal_Image_Name = Path.GetFileName(animalPicture.FileName);
                    animal.Animal_Image_Type = animalPicture.ContentType;
                    animal.Animal_Image      = bytes;
                }
                if (animal != null)
                {
                    Animal_Status status = db.Animal_Status.Where(zz => zz.Animal_Status_Name == "Available").FirstOrDefault();
                    if (status == null)
                    {
                        TempData["EditMessage"] = "";
                        return(RedirectToAction("AddTemporaryAnimal"));
                    }
                    animal.Animal_Status_ID = status.Animal_Status_ID;
                    db.Animals.Add(animal);
                    db.SaveChanges();
                }

                if (micro != null)
                {
                    Animal animalid = db.Animals.Where(zz => zz.Animal_Name == animal.Animal_Name && zz.Animal_Size == animal.Animal_Size && zz.Animal_Age == animal.Animal_Age && zz.Animal_Entry_Date == animal.Animal_Entry_Date).FirstOrDefault();
                    micro.Animal_ID = animalid.Animal_ID;
                    db.Microchips.Add(micro);
                    db.SaveChanges();
                }
                TempData["SuccessMessage"] = "";



                return(RedirectToAction("Index", "Employees"));
            }
            catch (Exception e)
            {
                TempData["EditMessage"] = e.Message;
                return(RedirectToAction("Index", "Employees"));
            }
        }
        public ActionResult Create([Bind(Include = "Vet_ID,Vet_Name,Vet_Emial,Vet_Tel,Vet_Address")] Veterinarian veterinarian)
        {
            if (ModelState.IsValid)
            {
                if (db.Veterinarians.Any(p => p.Vet_Name == veterinarian.Vet_Name)) //duplicate data
                {
                    ViewBag.Message = "Vet already exists";
                    /*ModelState.AddModelError("txtName", "Vet Name already exists.")*/
                }

                else
                {
                    db.Veterinarians.Add(veterinarian);
                    db.SaveChanges();
                    ViewBag.Message = "Success";
                    return(RedirectToAction("Index"));
                }
            }

            return(View(veterinarian));
        }
예제 #23
0
        public ActionResult ResetPassword(string EmailID)
        {
            //Verify Email ID
            //Generate Reset password link
            //Send Email
            string message = "";

            //bool status = false;

            using (Wollies_ShelterEntities dc = new Wollies_ShelterEntities())
            {
                //adding a employee
                //Employee emp = new Employee();
                //emp.Emp_Name = "jem";
                //emp.Emp_Email = "*****@*****.**";
                //dc.Employees.Add(emp);
                //dc.SaveChanges();

                //User_ useremp = new User_();
                //useremp.Emp_ID = 1;
                //useremp.Username = "******";
                //useremp.Password = "******";
                //dc.User_.Add(useremp);
                //dc.SaveChanges();
                var account = dc.Employees.Where(a => a.Emp_Email == EmailID).FirstOrDefault();
                if (account != null)
                {
                    var user = dc.User_.Where(a => a.Emp_ID == account.Emp_ID).FirstOrDefault();
                    if (user != null)
                    {
                        //Send email for reset password
                        string resetCode = Membership.GeneratePassword(12, 1);
                        SendVerificationLinkEmail(account.Emp_Email, resetCode, "ResetPassword");
                        user.Password = resetCode;
                        //This line I have added here to avoid confirm password not match issue , as we had added a confirm password property
                        //in our model class in part 1
                        dc.Configuration.ValidateOnSaveEnabled = false;
                        dc.SaveChanges();
                        message = "Reset password link has been sent to your email id.";
                    }
                    else
                    {
                        message = "Account not found";
                    }
                }
                else
                {
                    message = "Account not found";
                }
            }
            ViewBag.Message = message;
            return(View());
        }
        public ActionResult Create([Bind(Include = "Id,Animal_ID,Vet_Appointment_ID,Diagnosis_Details,Arrival_from_Vet,Next_Appointment_Date_,MedicalCard,Animal_Treatment")] Mecidal_Card mecidal_Card)
        {
            if (ModelState.IsValid)
            {
                db.Mecidal_Card.Add(mecidal_Card);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            List <Animal> animals  = db.Animals.ToList();
            List <Animal> animals2 = new List <Animal>();

            foreach (Animal item in animals)
            {
                if (item.Animal_Status_ID == 2)
                {
                    animals2.Add(item);
                }
            }
            ViewBag.Animal_ID          = new SelectList(animals2, "Animal_ID", "Animal_Name", mecidal_Card.Animal_ID);
            ViewBag.Vet_Appointment_ID = new SelectList(db.Vet_Appointment, "Vet_Appointment_ID", "Vet_Appointment_ID", mecidal_Card.Vet_Appointment_ID);
            return(View(mecidal_Card));
        }
예제 #25
0
        public JsonResult DeleteEvent(int eventID)
        {
            var status = false;

            using (Wollies_ShelterEntities dc = new Wollies_ShelterEntities())
            {
                var v = dc.Event_Schedule.Where(a => a.EventID == eventID).FirstOrDefault();
                if (v != null)
                {
                    dc.Event_Schedule.Remove(v);
                    dc.SaveChanges();
                    status = true;
                }
            }
            return(new JsonResult {
                Data = new { status = status }
            });
        }
예제 #26
0
        public ActionResult AddFosterCareParent(Foster_Care_Parent foster_Care_Parent, string button)
        {
            ViewBag.errorMessage = "";
            //Donation_Type asd = new Donation_Type();
            if (button == "Save")
            {
                try
                {
                    List <Foster_Care_Parent> foster_Care_Parents = new List <Foster_Care_Parent>();
                    foster_Care_Parents = db.Foster_Care_Parent.ToList();


                    if (foster_Care_Parents.Count != 0)
                    {
                        int count = 0;
                        foreach (var item in foster_Care_Parents)
                        {
                            if (item.Foster_Parent_Name == foster_Care_Parent.Foster_Parent_Name)
                            {
                                count++;
                                ViewBag.errorMessage = "There is a duplicate Donation Type Already";
                                return(View());
                            }
                        }
                        if (count == 0)
                        {
                            db.Foster_Care_Parent.Add(foster_Care_Parent);
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        db.Foster_Care_Parent.Add(foster_Care_Parent);
                        db.SaveChanges();
                    }
                }
                catch (Exception e)
                {
                    ViewBag.errorMessage = "There was an Error with network please try again: " + e.Message;
                    return(View());
                }
            }
            else if (button == "Cancel")
            {
                return(RedirectToAction("Index", "Home"));
            }
            return(RedirectToAction("Index", "Home"));
        }
예제 #27
0
 public ActionResult AddStock(Stock stock, string button)
 {
     try
     {
         if (button == "Save")
         {
             var searchstock = db.Stocks.Where(z => z.Packaging_Type_ID == stock.Packaging_Type_ID && z.Stock_Description == stock.Stock_Description && z.Unit_Type_ID == stock.Unit_Type_ID && z.Unit_number == stock.Unit_number).FirstOrDefault();
             if (searchstock == null)
             {
                 db.Stocks.Add(stock);
                 db.SaveChanges();
             }
             return(RedirectToAction("AddStock"));
         }
         if (button == "Cancel")
         {
         }
     }
     catch (Exception e)
     {
         return(RedirectToAction("AddStock"));
     }
     return(View("Index", "Home"));
 }
예제 #28
0
        public ActionResult Checkin(int?id)
        {
            id++;
            DateTime  datenow = DateTime.Now;
            TimeSheet time    = new TimeSheet();

            time.Emp_ID   = flex.employee.Emp_ID;
            time.Check_in = datenow;

            db.TimeSheets.Add(time);
            db.SaveChanges();
            var emp    = db.Employees.Where(z => z.Emp_ID == flex.employee.Emp_ID).FirstOrDefault();
            var empold = db.Employees.Where(z => z.Emp_ID == flex.employee.Emp_ID).FirstOrDefault();

            if (emp == null)
            {
                ViewBag.err = "Employee is not found";
                return(View());
            }
            empold.Employee_Status_ID = 1;
            db.Entry(emp).CurrentValues.SetValues(empold);
            db.SaveChanges();
            return(RedirectToAction("Index", "Home"));
        }
        public ActionResult Save(String NDate = "")
        {
            DateTime dd       = new DateTime();
            Adoption adoption = db.Adoptions.Find(Id);

            if (NDate != "")
            {
                String year  = NDate.Substring(0, 4);
                String month = NDate.Substring(5, 2);
                String day   = NDate.Substring(8, 2);
                dd = new DateTime(Convert.ToInt32(year), Convert.ToInt32(month), Convert.ToInt32(day));
            }


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



            adoption.Adopt_Status_ID = 2;

            HomeCheck obj = new HomeCheck();

            obj.Adoption_ID        = Id;
            obj.HomeCheck_Datetime = dd;
            db.HomeChecks.Add(obj);
            db.SaveChanges();
            myList = db.Adoptions.ToList();
            TempData["HCSCMessage"]      = "Please Save The Current HomeCheck on the Calendar Schedular";
            TempData["HomeCheckMessage"] = "HomeCheck Successfully Booked";
            //return View("HomeCheckSchedule");
            //return View("Index", myList);
            return(View("ScheduleHomeCheckCalendar"));
        }
        public ActionResult AddEmployee(int?Title, int?EmployeeType, Employee emp, User_ user, int?[] Role, string Gender, HttpPostedFileBase Contract)
        {
            Employee saveEmp = new Employee();

            try
            {
                if (Title == null || EmployeeType == null || emp == null)

                {
                    TempData["EditMessage"] = "Please Complete all the relevant information";
                    return(View("AddEmployee", innovation));
                }

                saveEmp = emp;
                //saveEmp.Emp_Gender = Gender;
                saveEmp.Title_ID    = Title;
                saveEmp.Emp_Type_ID = EmployeeType;

                //this is where we convert the contract to add to the database
                byte[] bytes;
                using (BinaryReader br = new BinaryReader(Contract.InputStream))
                {
                    bytes = br.ReadBytes(Contract.ContentLength);
                }
                saveEmp.Emp_Contract_Name = Path.GetFileName(Contract.FileName);
                saveEmp.Emp_Contract_Type = Contract.ContentType;
                saveEmp.Emp_Contract      = bytes;

                db.Employees.Add(saveEmp);
                db.SaveChanges();
                //Now we have to store the user
                //first look for the employee that we just added
                Employee searchemp = db.Employees.Where(z => z.Title_ID == saveEmp.Title_ID && z.Emp_Type_ID == saveEmp.Emp_Type_ID && z.Emp_Name == saveEmp.Emp_Name && z.Emp_Email == saveEmp.Emp_Email && z.Emp_Surname == saveEmp.Emp_Surname && z.Emp_IDNumber == saveEmp.Emp_IDNumber).FirstOrDefault();
                Employee old       = db.Employees.Where(z => z.Title_ID == saveEmp.Title_ID && z.Emp_Type_ID == saveEmp.Emp_Type_ID && z.Emp_Name == saveEmp.Emp_Name && z.Emp_Email == saveEmp.Emp_Email && z.Emp_Surname == saveEmp.Emp_Surname && z.Emp_IDNumber == saveEmp.Emp_IDNumber).FirstOrDefault();
                //then we add the employee id to the user that we created at the top
                if (searchemp == null)
                {
                    TempData["SuccessMessage"] = "Successfully added the employee";
                    return(View("AddEmployee", innovation));
                }
                if (user == null || Role == null)
                {
                    TempData["SuccessMessage"] = "Succesfully added the employee";
                    return(View("AddEmployee", innovation));
                }
                user.Emp_ID = searchemp.Emp_ID;
                TwoFactorAuthenticator tfa = new TwoFactorAuthenticator();
                string UserUniqueKey       = (user.Username + key);
                Session["UserUniqueKey"] = UserUniqueKey;
                var setupInfo = tfa.GenerateSetupCode("Wollies Shelter", user.Username, UserUniqueKey, 300, 300);
                searchemp.BarcodeImageUrl = setupInfo.QrCodeSetupImageUrl;
                ViewBag.Qr = setupInfo.QrCodeSetupImageUrl;
                db.Entry(old).CurrentValues.SetValues(searchemp);
                db.SaveChanges();
                //var md5 = new MD5CryptoServiceProvider();
                //var pass = md5.ComputeHash(Convert.FromBase64String(user.Password));
                //user.Password = pass;
                //we store the info

                db.User_.Add(user);
                db.SaveChanges();
                //we store the User acces that is needed
                User_ searchuser = db.User_.Where(z => z.Emp_ID == searchemp.Emp_ID).FirstOrDefault();

                if (searchuser == null)
                {
                    return(View("AddEmployee", innovation));
                }

                foreach (var item in Role)
                {
                    UserRole userRole = new UserRole();
                    userRole.UserID  = searchuser.UserID;
                    userRole.Role_ID = item;
                    db.UserRoles.Add(userRole);
                    db.SaveChanges();
                    TempData["SuccessMessage"] = "Succesfully added the User";
                }
                user = searchuser;

                TempData["SuccessMessage"] = "Succesfully added the User";
                return(View("BarCodeGenerated", user));
            }


            catch (Exception e)
            {
                TempData["EditMessage"] = e.Message;
                return(RedirectToAction("AddEmployee"));
            }
        }