Exemple #1
0
        public ActionResult Delegate_Authority_Staff(FormCollection form_data)
        {
            string staff_name      = form_data["staff_list"];
            string duty_start_date = form_data["start_date_box"].ToString();
            string duty_end_date   = form_data["end_date_box"].ToString();

            List <staff_representative> list = StaffRepData.GetAllNotExpired();

            foreach (staff_representative st in list)
            {
                if (StaffData.GetStaffById(st.staff_representativeId).name.Equals(staff_name))
                {
                    return(RedirectToAction("Delegate_Authority", "Head"));
                }
            }

            using (var db = new DataBaseContext())
            {
                staff staff_obj = db.staff_repository.Where(s => s.name == staff_name).FirstOrDefault();

                staff_representative staff_representative_obj = new staff_representative(duty_start_date, duty_end_date, staff_obj, "Pending");

                db.staff_representative_repository.Add(staff_representative_obj);
                db.SaveChanges();

                if (duty_start_date.Equals(DateTime.Today.Date.ToString("yyyy-MM-dd")))
                {
                    StaffRepData.StartDelegation(staff_obj.staffId);
                }
            }



            //Email Notification
            staff  sta      = StaffData.GetStaffByName(staff_name);
            string emailadd = sta.email;
            Task   task     = Task.Run(() => {
                EmailNotification.SendNotificationEmailToEmployee(emailadd, "New Delegation Reminder", "Your were just be delegated as temporary department head, please check it out.");
            });

            return(RedirectToAction("Delegate_Authority", "Head"));
        }