Example #1
0
        public ActionResult Create(Student student)
        {
            bool   already = true;
            string error   = string.Empty;

            if (ModelState.IsValid)
            {
                already = Checking(student);

                if (already)
                {
                    db.Students.Add(student);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            error = "Студент " + student.Surname + " " + student.Name + " " + student.LastName + " є в базі даних";
            ModelState.AddModelError(string.Empty, error);
            ViewBag.Group_ID = new SelectList((from s in db.Groups
                                               select new
            {
                Group_ID = s.Group_ID,
                FullGroup = s.Name + " " + s.EnrollmentYear
            }), "Group_ID", "FullGroup", student.Group_ID);
            return(View(student));
        }
Example #2
0
        public ActionResult Registration([Bind(Exclude = "IsEmailVerified,ActivationCode")] Users user)
        {
            bool   Status  = false;
            string message = "";

            if (ModelState.IsValid)
            {
                #region
                var isExist = IsEmailExist(user.Email);
                if (isExist)
                {
                    ModelState.AddModelError("EmailExist", "Електронна пошта вже існує");
                    return(View(user));
                }
                #endregion

                #region
                if (user.StatusID == "Працівник")
                {
                    var isEmployerExist = IsEmployerExist(user.IDEmployer);
                    if (!isEmployerExist)
                    {
                        ModelState.AddModelError("EmployerExist", "Такого керівника не існує");
                        return(View(user));
                    }
                }
                #endregion

                #region Generate Activation Code
                user.ActivationCode = Guid.NewGuid();
                #endregion

                #region  Password Hashing
                user.Password        = Crypto.Hash(user.Password);
                user.ConfirmPassword = Crypto.Hash(user.ConfirmPassword);
                #endregion
                user.IsEmailVerified = false;

                #region Save to Database
                using (ScheduleEntities dc = new ScheduleEntities())
                {
                    dc.Users.Add(user);
                    dc.SaveChanges();

                    SendVerificationLinkEmail(user.Email, user.ActivationCode.ToString());
                    message = "Реєстрація успішно виконана. Посилання для активації облікового запису " +
                              " було надіслано на вашу електронну пошту: " + user.Email;
                    Status = true;
                }
                #endregion
            }
            else
            {
                message = "Невірний запит";
            }

            ViewBag.Message = message;
            ViewBag.Status  = Status;
            return(View(user));
        }
Example #3
0
        //Update database record
        private void UpdateAppointment()
        {
            try
            {
                using (ent = new ScheduleEntities())
                {
                    var currentAppointment = ent.appointments.Attach(AppointmentIndex);

                    currentAppointment.customerId = selectedCustomerID;
                    currentAppointment.userId     = ActiveUser.userId;

                    currentAppointment.title       = title_TextBox.Text;
                    currentAppointment.location    = location_TextBox.Text;
                    currentAppointment.contact     = contact_TextBox.Text;
                    currentAppointment.type        = type_TextBox.Text;
                    currentAppointment.url         = url_TextBox.Text;
                    currentAppointment.description = description_TextBox.Text;

                    currentAppointment.start = start_TimePicker.Value.ToUniversalTime();
                    currentAppointment.end   = end_TimePicker.Value.ToUniversalTime();

                    currentAppointment.lastUpdate   = CurrentTime;
                    currentAppointment.lastUpdateBy = ActiveUser.userName;

                    ent.SaveChanges();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        public JsonResult SaveEvent(Events e)
        {
            var status = false;

            using (ScheduleEntities dc = new ScheduleEntities())
            {
                var username = User.Identity.Name;
                var u        = dc.Users.Where(t => t.Email == username).FirstOrDefault();
                if (e.EventID > 0)
                {
                    var v = dc.Events.Where(a => a.EventID == e.EventID).FirstOrDefault();
                    if (v != null)
                    {
                        v.Subject     = e.Subject;
                        v.Start       = e.Start;
                        v.End         = e.End;
                        v.Description = e.Description;
                        v.IsFullDay   = e.IsFullDay;
                        v.ThemeColor  = e.ThemeColor;
                        v.UserID      = u.UserID;
                    }
                }
                else
                {
                    e.UserID = u.UserID;
                    dc.Events.Add(e);
                }

                dc.SaveChanges();
                status = true;
            }
            return(new JsonResult {
                Data = new { status = status }
            });
        }
Example #5
0
        ////Country Controls
        private void addCountry_Button_Click(object sender, EventArgs e)
        {
            if (!IsNewCountryValid())
            {
                return;
            }

            try
            {
                using (ent = new ScheduleEntities())
                {
                    var newCountry = new country
                    {
                        countryName  = countryName_TextBox.Text,
                        createDate   = UserTracker.CurrentTime,
                        createdBy    = UserTracker.ActiveUser.userName,
                        lastUpdate   = UserTracker.CurrentTime,
                        lastUpdateBy = UserTracker.ActiveUser.userName
                    };

                    ent.countries.Add(newCountry);
                    ent.SaveChanges();

                    PopulateCountryComboBox();
                    countryName_TextBox.Text = "";
                    MessageBox.Show($"'{newCountry.countryName}' was added", "New Country");
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Something went wrong", "Error");
            }
        }
Example #6
0
        private void save_Button_Click(object sender, EventArgs e)
        {
            if (!IsNewCustomerValid())
            {
                return;
            }

            using (ent = new ScheduleEntities())
            {//adds new customer
                var newCustomer = new customer()
                {
                    customerName = name_TextBox.Text,
                    active       = IsActive(),
                    createDate   = UserTracker.CurrentTime,
                    createdBy    = UserTracker.ActiveUser.userName,
                    lastUpdate   = UserTracker.CurrentTime,
                    lastUpdateBy = UserTracker.ActiveUser.userName,
                    addressId    = selectedAddressID
                };

                ent.customers.Add(newCustomer);
                ent.SaveChanges();
            }

            AddCust_SaveClicked(this, e);
            this.Close();
        }
Example #7
0
        //
        // GET: /Grade/



        public ActionResult Index(int?groupID, int?scheduleID)
        {
            var students = from s in db.Students
                           where s.Group_ID == groupID
                           select s;
            Grade        gr;
            List <Grade> grList = new List <Grade>();

            bool checkGR = true;

            foreach (var st in students)
            {
                gr             = new Grade();
                checkGR        = true;
                gr.Student_ID  = st.Student_ID;
                gr.Schedule_ID = Convert.ToInt32(scheduleID);
                gr.Grade_ID    = 1;

                foreach (var check in db.Grades)
                {
                    if (gr.Student_ID == check.Student_ID && gr.Schedule_ID == check.Schedule_ID)
                    {
                        checkGR = false;
                    }
                }

                if (checkGR)
                {
                    grList.Add(gr);
                }
            }
            foreach (var item in grList)
            {
                db.Grades.Add(item);
                db.SaveChanges();
            }
            var grade = db.Grades.Include(g => g.Schedule).Include(g => g.Student);

            grade = from s in grade
                    where s.Schedule_ID == scheduleID
                    orderby s.Student.Surname
                    select s;



            return(View(grade.ToList()));
        }
Example #8
0
        public ActionResult Create(Teacher teacher)
        {
            bool   already = false;
            string error   = string.Empty;

            if (ModelState.IsValid)
            {
                already = Checking(teacher);

                if (already)
                {
                    db.Teachers.Add(teacher);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            error = "Викладач " + teacher.Surname + " " + teacher.Name + " " + teacher.LastName + " є в базі даних";
            ModelState.AddModelError(string.Empty, error);
            return(View(teacher));
        }
Example #9
0
        public ActionResult Create(Subject subject)
        {
            bool   already = true;
            string error   = string.Empty;

            if (ModelState.IsValid)
            {
                already = Checking(subject);

                if (already)
                {
                    db.Subjects.Add(subject);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            error = "Предмет " + subject.Name + " є в базі даних";
            ModelState.AddModelError(string.Empty, error);
            return(View(subject));
        }
Example #10
0
        public ActionResult Create(LessonType lessontype)
        {
            bool   already = true;
            string error   = string.Empty;

            if (ModelState.IsValid)
            {
                already = Checking(lessontype);

                if (already)
                {
                    db.LessonTypes.Add(lessontype);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            error = "Тип заняття " + lessontype.Type + " є в базі даних";
            ModelState.AddModelError(string.Empty, error);
            return(View(lessontype));
        }
Example #11
0
        public ActionResult Create(Classroom classroom)
        {
            bool   roomAlready  = true;
            string errorMessage = String.Empty;

            if (ModelState.IsValid)
            {
                //check if such classroom isn't in DB
                roomAlready = Checking(classroom);


                if (roomAlready)
                {
                    db.Classrooms.Add(classroom);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            errorMessage = "Аудиторія " + classroom.Number + " є в базі даних";
            ModelState.AddModelError(string.Empty, errorMessage);
            return(View(classroom));
        }
Example #12
0
        public ActionResult Create(Group group)
        {
            bool   groupAlready = true;
            string errorMessage = String.Empty;


            if (ModelState.IsValid)
            {
                //check if such group isn't in DB
                groupAlready = Checking(group);

                if (groupAlready)
                {
                    db.Groups.Add(group);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            errorMessage = "Група " + group.Name + " " + group.EnrollmentYear + " є базі даних";
            ModelState.AddModelError(string.Empty, errorMessage);
            return(View(group));
        }
        public JsonResult DeleteEvent(int eventID)
        {
            var status = false;

            using (ScheduleEntities dc = new ScheduleEntities())
            {
                var v = dc.Events.Where(a => a.EventID == eventID).FirstOrDefault();
                if (v != null)
                {
                    dc.Events.Remove(v);
                    dc.SaveChanges();
                    status = true;
                }
            }
            return(new JsonResult {
                Data = new { status = status }
            });
        }
Example #14
0
    /* No longer needed
     * private void RefreshSession()
     * {
     *  using (ScheduleEntities dbcon = new ScheduleEntities())
     *  {
     *
     *      if (Session.Count > 0)
     *      {
     *          studentName = Session["User"].ToString();
     *
     *          var studentNameToId =
     *              (from stu in dbcon.StudentTables
     *               where stu.StudentUserName == studentName
     *               select stu).First();
     *
     *          Session.Add("StdID", studentNameToId.StudentID);
     *
     *          studentID = Convert.ToInt32(Session["StdID"].ToString());
     *      }
     *  }
     * } */

    //Add button
    protected void addBtn_Click(object sender, EventArgs e)
    {
        using (ScheduleEntities dbcon = new ScheduleEntities())
        {
            var studentIDToAdvisorID =
                (from apt in dbcon.AppointmentTables
                 where apt.StudentID == studentID
                 select apt).First();

            int advisorID = studentIDToAdvisorID.AdvisorID;

            var advisorDates =
                (from date in dbcon.AdvisorTables
                 where date.AdvisorID == advisorID
                 select date).First();



            if (true /*Calendar1.SelectedDate.ToString() >= advisorDates.advisorStartDate &&
                      * Calendar1.SelectedDate.ToString() <= advisorDates.advisorEndDate*/)
            {
                AppointmentTable app = new AppointmentTable();

                app.StudentID         = studentID;
                app.AdvisorID         = advisorID;
                app.AppointmentDate   = Convert.ToDateTime(Calendar1.SelectedDate.ToString());
                app.AppointmentTime   = TimeSpan.Parse(TextBox2.Text);
                app.AppointmentReason = TextBox3.Text;

                // add data to the table
                dbcon.AppointmentTables.Add(app);
                dbcon.SaveChanges();
            }
            else
            {
            }
        }
        // show data in the GridView
        GridView1.DataBind();
    }
        private void save_Button_Click(object sender, EventArgs e)
        {
            if (!IsValid())
            {
                return;
            }

            using (ent = new ScheduleEntities())
            {
                //update record in the table
                var currentRecord = ent.customers.Attach(CustomerIndex);
                currentRecord.customerName = name_TextBox.Text;
                currentRecord.addressId    = selectedAddressID;
                currentRecord.active       = IsActive();
                currentRecord.lastUpdate   = CurrentTime;
                currentRecord.lastUpdateBy = ActiveUser.userName;
                ent.SaveChanges();
            }

            UpCust_SaveClicked(this, e);
            this.Close();
        }
Example #16
0
    //Delete Button
    protected void Button1_Click(object sender, EventArgs e)
    {
        using (ScheduleEntities dbcon = new ScheduleEntities())
        {
            if (GridView1.SelectedDataKey.Value != null)
            {
                // add data to the dbcon

                // select the row
                int item = Convert.ToInt32(
                    GridView1.SelectedDataKey.Value.ToString());

                AppointmentTable app = (from x in dbcon.AppointmentTables
                                        where x.AppointmentID == item
                                        select x).First();

                //delete row from the table
                dbcon.AppointmentTables.Remove(app);
                dbcon.SaveChanges();
            }
        }
        GridView1.DataBind();
    }
Example #17
0
        public ActionResult VerifyAccount(string id)
        {
            bool Status = false;

            using (ScheduleEntities dc = new ScheduleEntities())
            {
                dc.Configuration.ValidateOnSaveEnabled = false;

                var v = dc.Users.Where(a => a.ActivationCode == new Guid(id)).FirstOrDefault();
                if (v != null)
                {
                    v.IsEmailVerified = true;
                    dc.SaveChanges();
                    Status = true;
                }
                else
                {
                    ViewBag.Message = "Невірний запит";
                }
            }
            ViewBag.Status = Status;
            return(View());
        }
Example #18
0
    /* No longer needed
     * private void RefreshSession()
     * {
     *  using (ScheduleEntities dbcon = new ScheduleEntities())
     *  {
     *
     *      if (Session.Count > 0)
     *      {
     *          advisorName = Session["User"].ToString();
     *
     *          var advisorNameToId =
     *              (from adv in dbcon.AdvisorTables
     *               where adv.AdvisorUserName == advisorName
     *               select adv).First();
     *
     *          Session.Add("AdvID", advisorNameToId.AdvisorID);
     *
     *          advisorID = Convert.ToInt32(Session["AdvID"].ToString());
     *      }
     *
     *      //Add button
     *  }
     * } */

    protected void addBtn_Click(object sender, EventArgs e)
    {
        using (ScheduleEntities dbcon = new ScheduleEntities())
        {
            AppointmentTable app = new AppointmentTable();


            app.AppointmentDate   = Convert.ToDateTime(Calendar1.SelectedDate.ToString());
            app.AppointmentTime   = TimeSpan.Parse(TextBox2.Text);
            app.AppointmentReason = TextBox3.Text;

            app.AdvisorID = advisorID;

            var advisorIDToStudentID =
                (from apt in dbcon.AppointmentTables
                 where apt.AdvisorID == advisorID
                 select apt).First();

            app.StudentID = advisorIDToStudentID.StudentID;

            // add data to the table
            dbcon.AppointmentTables.Add(app);
            dbcon.SaveChanges();

            var StudentIDToName =
                (from x in dbcon.StudentTables
                 where x.StudentID == advisorIDToStudentID.StudentID
                 select x).First();

            string studentName = StudentIDToName.StudentFirstName + " " + StudentIDToName.StudentLastName;

            notifLb.Text = "Appointment has been created for " + Calendar1.SelectedDate.ToString() + " at " + TextBox2.Text + " with " + studentName;
        }

        // show data in the GridView
        GridView1.DataBind();
    }
Example #19
0
        ////Address Controls
        private void addAddress_Button_Click(object sender, EventArgs e)
        {
            if (!IsNewAddressValid())
            {
                return;
            }

            try
            {
                using (ent = new ScheduleEntities())
                {
                    var newAddress = new address()
                    {
                        address1     = address1_TextBox.Text,
                        address2     = address2_TextBox.Text,
                        cityId       = selectedCityID,
                        postalCode   = postal_TextBox.Text,
                        phone        = phone_TextBox.Text,
                        createDate   = UserTracker.CurrentTime,
                        createdBy    = UserTracker.ActiveUser.userName,
                        lastUpdate   = UserTracker.CurrentTime,
                        lastUpdateBy = UserTracker.ActiveUser.userName
                    };

                    ent.addresses.Add(newAddress);
                    ent.SaveChanges();

                    PopulateAddressComboBox();
                    ClearAddressFields();
                    MessageBox.Show($"'{newAddress.address1}' was added", "New Address");
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Something went wrong", "Error");
            }
        }
Example #20
0
        //Delete Appointment
        private void apptDelete_Button_Click(object sender, EventArgs e)
        {
            if (IsIndexNull(AppointmentIndex, "Appointment", "Delete"))
            {
                return;
            }

            var messageDeleteAppointment = MessageBox.Show($"Are you sure you want to delete appointment with ID {AppointmentIndex.appointmentId}?", "Delete Appointment", MessageBoxButtons.YesNo);

            if (messageDeleteAppointment == DialogResult.Yes)
            {
                using (ent = new ScheduleEntities())
                {
                    ent.appointments.Attach(AppointmentIndex);
                    ent.appointments.Remove(AppointmentIndex);
                    ent.SaveChanges();

                    PopulateAppointmentGrid();
                    appointments_DataGrid.DataSource = userAppointments;
                    DeselectRows();
                    AppointmentIndex = null;
                }
            }
        }
Example #21
0
        //Delete Customer
        private void custDelete_Button_Click(object sender, EventArgs e)
        {
            if (IsIndexNull(CustomerIndex, "Customer", "Delete"))
            {
                return;
            }

            var messageDeleteCustomer = MessageBox.Show($"Are you sure you want to delete record '{CustomerIndex.customerName}'?", "Delete Customer", MessageBoxButtons.YesNo);

            if (messageDeleteCustomer == DialogResult.Yes)
            {
                using (ent = new ScheduleEntities())
                {
                    ent.customers.Attach(CustomerIndex);
                    ent.customers.Remove(CustomerIndex);
                    ent.SaveChanges();

                    PopulateCustomerGrid();
                    customer_DataGrid.DataSource = userCustomers;
                    DeselectRows();
                    CustomerIndex = null;
                }
            }
        }
Example #22
0
        //Adds a new appointment to the database
        private void AddAppointment()
        {
            try
            {
                using (ent = new ScheduleEntities())
                {
                    var newAppointment = new appointment
                    {
                        customerId = selectedCustomerID,
                        userId     = ActiveUser.userId,

                        title       = title_TextBox.Text,
                        description = description_TextBox.Text,
                        location    = location_TextBox.Text,
                        contact     = contact_TextBox.Text,
                        type        = type_TextBox.Text,
                        url         = url_TextBox.Text,

                        start = start_TimePicker.Value.ToUniversalTime(),
                        end   = end_TimePicker.Value.ToUniversalTime(),

                        createDate   = CurrentTime,
                        createdBy    = ActiveUser.userName,
                        lastUpdate   = CurrentTime,
                        lastUpdateBy = ActiveUser.userName
                    };

                    ent.appointments.Add(newAppointment);
                    ent.SaveChanges();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }