Esempio n. 1
0
        public ActionResult AppointStaffApi(string staffname, string getStartDate, string getEndDate)
        {
            var      result        = db.DepartmentStaff.SingleOrDefault(b => b.StaffName == staffname);
            var      resultStaffId = result.StaffId;
            string   resultDeptId  = result.DeptId;
            DateTime fromDate      = DateTime.ParseExact(getStartDate, "MM/dd/yyyy HH:mm:ss",
                                                         CultureInfo.InvariantCulture);
            DateTime toDate = DateTime.ParseExact(getEndDate, "MM/dd/yyyy HH:mm:ss",
                                                  CultureInfo.InvariantCulture);

            using (LogicEntities db = new LogicEntities())
            {
                var authorization = db.Set <logicProject.Models.EF.Authorization>();
                authorization.Add(new logicProject.Models.EF.Authorization {
                    DeptId = resultDeptId, StaffId = resultStaffId, StartDate = fromDate, EndDate = toDate
                });
                db.SaveChanges();
            }
            List <string> email = new List <string>();

            email.Add(result.StaffEmail);
            string message = Utility.EmailBody.HeadBody + getStartDate + " and will expired on " + getEndDate;

            Utility.EmailService.SendEmail(email, Utility.EmailBody.HeadSubject, message);
            return(Json(new { isok = true, message = "Authorization Successful" }));
        }
Esempio n. 2
0
        public ActionResult AppointStaff(string staffname, DateTime getStartDate, DateTime getEndDate)
        {
            var    result        = db.DepartmentStaff.SingleOrDefault(b => b.StaffName == staffname);
            var    resultStaffId = result.StaffId;
            string resultDeptId  = result.DeptId;
            var    list          = db.Authorization.Where(x => x.DeptId == resultDeptId && x.EndDate >= getStartDate && x.StartDate <= getEndDate).ToList();

            if (list.Count > 0)
            {
                return(Json(new { isok = false, message = "Authorization Unsuccessful" }));
            }
            using (LogicEntities db = new LogicEntities())
            {
                var authorization = db.Set <logicProject.Models.EF.Authorization>();
                authorization.Add(new logicProject.Models.EF.Authorization {
                    DeptId = resultDeptId, StaffId = resultStaffId, StartDate = getStartDate, EndDate = getEndDate
                });
                db.SaveChanges();
            }
            List <string> email = new List <string>();

            email.Add(result.StaffEmail);
            string message = Utility.EmailBody.HeadBody + getStartDate.ToString("dddd, dd MMMM yyyy") + " and will expired on " + getEndDate.ToString("dddd, dd MMMM yyyy");

            Utility.EmailService.SendEmail(email, Utility.EmailBody.HeadSubject, message);
            return(Json(new { isok = true, message = "Authorization Successful", redirect = "/DeptHead/AuthorizeStaff" }));
        }
        public ActionResult AppointStaff(string staffname, DateTime getStartDate, DateTime getEndDate)
        {
            var result        = db.DepartmentStaff.SingleOrDefault(b => b.StaffName == staffname);
            var resultStaffId = result.StaffId;
            var resultDeptId  = int.Parse(result.DeptId);

            //Debug.WriteLine("staff id is:" + resultId);

            using (LogicEntities db = new LogicEntities())
            {
                //DateTime now = DateTime.Now;
                var authorization = db.Set <Authorization>();
                authorization.Add(new Authorization {
                    AuthNo = 1, DeptId = resultDeptId, StaffId = resultStaffId, StartDate = getStartDate, EndDate = getEndDate
                });
                db.SaveChanges();
            }
            return(Json(new { isok = true, message = "Authorization Successful" }));
        }