public IHttpActionResult GET(string dateAndTime, string username)
        {
            var    identity          = User.Identity as ClaimsIdentity;
            string authenticatedUser = identity.FindFirst("sub").Value;

            DateTime dt;

            if (!DateTime.TryParse(dateAndTime, out dt))
            {
                return(BadRequest("wrong format on dateAndTime"));
            }

            try
            {
                StaffModel user = _staffServices.Get(authenticatedUser);
                if (user.isAdmin)
                {
                    StaffModel  userToGet = _staffServices.Get(username);
                    string      date      = dateAndTime.Substring(0, 10);
                    StaffModels staffs    = new StaffModels(_kronox.getSchedule(userToGet.roomNr, date));
                    StaffModel  staff     = _staffServices.Get(userToGet.staffId);
                    staff.schedules.AddRange(_scheduleServices.List(userToGet.roomNr));
                    staffs.staffModels.Add(staff);
                    return(Json(staffs));
                }
                else
                {
                    return(BadRequest("Action not allowed for current user"));
                }
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Exemplo n.º 2
0
        public HttpResponseMessage PostLogin(StaffModels item)
        {
            string    errMsg  = "";
            DataSet   ds      = new DataSet();
            DataTable dt      = new DataTable();
            Result    resData = new Result();

            dt = repository.Login(item.StaffLogin, item.StaffPassword, ref errMsg);

            ds.Tables.Add(dt);
            if (dt.Rows.Count <= 0 && errMsg == "")
            {
                errMsg = "รหัสพนักงาน/รหัสผ่าน ไม่ถูกต้อง." + Environment.NewLine + "โปรดตรวจสอบ รหัสพนักงาน/รหัสผ่าน ก่อน login เข้าระบบอีกครั้ง";
            }
            if (errMsg != "")
            {
                resData.StatusCode = (int)(StatusCodes.Error);
                resData.Messages   = errMsg;
            }
            else
            {
                resData.StatusCode = (int)(StatusCodes.Succuss);
                resData.Messages   = (String)EnumString.GetStringValue(StatusCodes.Succuss);
            }

            resData.Results = ds;
            resData.Records = ds.Tables[0].Rows.Count;
            return(Request.CreateResponse(HttpStatusCode.OK, resData));
        }
Exemplo n.º 3
0
        public IHttpActionResult GET(int corridorNr)
        {
            var    identity          = User.Identity as ClaimsIdentity;
            string authenticatedUser = identity.FindFirst("sub").Value;

            try
            {
                StaffModel user = _staffServices.Get(authenticatedUser);
                if (user.isAdmin)
                {
                    StaffModels staffs = new StaffModels();
                    staffs.staffModels = _staffServices.List(corridorNr);
                    return(Json(staffs));
                }
                return(BadRequest("Permission denied"));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Process staff in same divisions who are also on leave
        /// </summary>
        /// <param name="staff"></param>
        /// <returns></returns>
        protected sealed override string BuildOtherDetails()
        {
            var details = new StringBuilder();

            if (StaffModels == null)
            {
                return(String.Empty);
            }
            details.Append(string.Format("<table><th>Staff Name</th><th>Leave Start</th><th>Leave End</th><th>Application Status</th>"));
            StaffModels.ToList().ForEach(m =>
            {
                var otherStaffLeave = OtherStaffGoingOnLeave(m, LeaveModel.LeaveDateStart, LeaveModel.LeaveDateEnd).ToList();
                if (otherStaffLeave.Any())
                {
                    otherStaffLeave.ToList().ForEach(x =>
                                                     details.Append(string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>",
                                                                                  m.StaffFullName, x.LeaveDateStart.ToShortDateString(), x.LeaveDateEnd.ToShortDateString(), ((LeaveStatus)x.LeaveStatus).ToString())));
                }
            });

            details.Append(string.Format("</table>"));

            return(details.ToString());
        }
        /// <summary>
        /// Returns users avaibility
        /// </summary>
        /// <param name="dateAndTime"> Date need format yyyy-mm-dd hh:mm:ss</param>
        /// <returns></returns>
        public bool Get(string dateAndTime, string username)
        {
            try
            {
                string date        = dateAndTime.Substring(0, 10);
                string time        = dateAndTime.Substring(11, 5);
                bool   isAvailable = true;
                //set false if Lunchtime
                if (Convert.ToInt32(dateAndTime.Substring(12, 1)) == 2)
                {
                    isAvailable = false;
                }
                StaffModel user = _staffServices.Get(username);

                //checks with kronox schedule if current user is available or not
                StaffModels staffmodels = new StaffModels(_kronox.getSchedule(user.roomNr, date));

                for (int i = 0; i < staffmodels.staffModels.Count; i++)
                {
                    StaffModel staff = staffmodels.staffModels[i];
                    for (int k = 0; k < staff.schedules.Count; k++)
                    {
                        string from = staff.schedules[k].from;
                        string to   = staff.schedules[k].to;
                        if (Convert.ToInt32(from.Substring(0, 2)) <= Convert.ToInt32(time.Substring(0, 2)) &&
                            Convert.ToInt32(from.Substring(3, 2)) <= Convert.ToInt32(time.Substring(3, 2)))
                        {
                            if (Convert.ToInt32(to.Substring(0, 2)) == Convert.ToInt32(time.Substring(0, 2)) &&
                                Convert.ToInt32(to.Substring(3, 2)) >= Convert.ToInt32(time.Substring(3, 2)))
                            {
                                isAvailable = false;
                            }
                            else if (Convert.ToInt32(to.Substring(0, 2)) > Convert.ToInt32(time.Substring(0, 2)))
                            {
                                isAvailable = false;
                            }
                        }
                    }
                }

                //Check Database schadules
                List <Schedule> schedule = CustomMapper.MapTo.Schedules(_taskRepository.List(user.roomNr, date));
                for (int i = 0; i < schedule.Count; i++)
                {
                    string from = schedule[i].from;
                    string to   = schedule[i].to;
                    if (Convert.ToInt32(from.Substring(0, 2)) <= Convert.ToInt32(time.Substring(0, 2)) &&
                        Convert.ToInt32(from.Substring(3, 2)) <= Convert.ToInt32(time.Substring(3, 2)))
                    {
                        if (Convert.ToInt32(to.Substring(0, 2)) == Convert.ToInt32(time.Substring(0, 2)) &&
                            Convert.ToInt32(to.Substring(3, 2)) >= Convert.ToInt32(time.Substring(3, 2)))
                        {
                            isAvailable = schedule[i].isAvailable;
                        }
                        else if (Convert.ToInt32(to.Substring(0, 2)) > Convert.ToInt32(time.Substring(0, 2)))
                        {
                            isAvailable = schedule[i].isAvailable;
                        }
                    }
                }
                return(isAvailable);
            }

            catch (Exception)
            {
                throw;
            }
        }
        //string setToDateAndTime(ScheduleModel scheduleModel, string username)
        public string Post(ScheduleModel scheduleModel, string username)
        {
            StaffModel user = _staffServices.Get(username);

            //Set toDateAndTime if null start ----------------------------------->
            if (scheduleModel.toDateAndTime == null)
            {
                //Check with database
                List <Schedule> lSchedule = CustomMapper.MapTo.Schedules(_taskRepository.List(user.roomNr)).OrderBy(x => x.from).ToList();
                if (lSchedule.Count != 0)
                {
                    foreach (Schedule s in lSchedule)
                    {
                        if (Convert.ToInt32(scheduleModel.fromDateAndTime.Substring(11, 2)) == Convert.ToInt32(s.from.Substring(0, 2)))
                        {
                            if (scheduleModel.toDateAndTime == null)
                            {
                                scheduleModel.toDateAndTime = scheduleModel.fromDateAndTime.Substring(0, 11) + s.to + ":59";
                            }

                            else if (Convert.ToInt32(scheduleModel.toDateAndTime.Substring(11, 2)) == Convert.ToInt32(s.from.Substring(0, 2)) &&
                                     Convert.ToInt32(scheduleModel.toDateAndTime.Substring(14, 2)) > Convert.ToInt32(s.from.Substring(3, 2)))
                            {
                                scheduleModel.toDateAndTime = scheduleModel.fromDateAndTime.Substring(0, 11) + s.from + ":59";
                            }

                            else if (Convert.ToInt32(scheduleModel.toDateAndTime.Substring(11, 2)) > Convert.ToInt32(s.from.Substring(0, 2)))
                            {
                                scheduleModel.toDateAndTime = scheduleModel.fromDateAndTime.Substring(0, 11) + s.from + ":59";
                            }
                        }

                        else if (Convert.ToInt32(scheduleModel.fromDateAndTime.Substring(11, 2)) < Convert.ToInt32(s.from.Substring(0, 2)))
                        {
                            if (scheduleModel.toDateAndTime == null)
                            {
                                scheduleModel.toDateAndTime = scheduleModel.fromDateAndTime.Substring(0, 11) + s.from + ":59";
                            }

                            else if (Convert.ToInt32(scheduleModel.toDateAndTime.Substring(11, 2)) == Convert.ToInt32(s.from.Substring(0, 2)) &&
                                     Convert.ToInt32(scheduleModel.toDateAndTime.Substring(14, 2)) > Convert.ToInt32(s.from.Substring(3, 2)))
                            {
                                scheduleModel.toDateAndTime = scheduleModel.fromDateAndTime.Substring(0, 11) + s.from + ":59";
                            }

                            else if (Convert.ToInt32(scheduleModel.toDateAndTime.Substring(11, 2)) > Convert.ToInt32(s.from.Substring(0, 2)))
                            {
                                scheduleModel.toDateAndTime = scheduleModel.fromDateAndTime.Substring(0, 11) + s.from + ":59";
                            }
                        }
                    }
                }
                //Check with database
                StaffModels staffmodels = new StaffModels(_kronox.getSchedule(user.roomNr, scheduleModel.fromDateAndTime.Substring(0, 10)));
                if (staffmodels.staffModels.Count != 0)
                {
                    foreach (StaffModel sM in staffmodels.staffModels)
                    {
                        foreach (Schedule s in sM.schedules)
                        {
                            if (Convert.ToInt32(scheduleModel.fromDateAndTime.Substring(11, 2)) == Convert.ToInt32(s.from.Substring(0, 2)) &&
                                Convert.ToInt32(scheduleModel.fromDateAndTime.Substring(14, 2)) < Convert.ToInt32(s.from.Substring(3, 2)))
                            {
                                if (scheduleModel.toDateAndTime == null)
                                {
                                    scheduleModel.toDateAndTime = scheduleModel.fromDateAndTime.Substring(0, 11) + s.from + ":59";
                                }

                                else if (Convert.ToInt32(scheduleModel.toDateAndTime.Substring(11, 2)) == Convert.ToInt32(s.from.Substring(0, 2)) &&
                                         Convert.ToInt32(scheduleModel.toDateAndTime.Substring(14, 2)) > Convert.ToInt32(s.from.Substring(3, 2)))
                                {
                                    scheduleModel.toDateAndTime = scheduleModel.fromDateAndTime.Substring(0, 11) + s.from + ":59";
                                }

                                else if (Convert.ToInt32(scheduleModel.toDateAndTime.Substring(11, 2)) > Convert.ToInt32(s.from.Substring(0, 2)))
                                {
                                    scheduleModel.toDateAndTime = scheduleModel.fromDateAndTime.Substring(0, 11) + s.from + ":59";
                                }
                            }

                            else if (Convert.ToInt32(scheduleModel.fromDateAndTime.Substring(11, 2)) < Convert.ToInt32(s.from.Substring(0, 2)))
                            {
                                if (scheduleModel.toDateAndTime == null)
                                {
                                    scheduleModel.toDateAndTime = scheduleModel.fromDateAndTime.Substring(0, 11) + s.from + ":59";
                                }

                                else if (Convert.ToInt32(scheduleModel.toDateAndTime.Substring(11, 2)) == Convert.ToInt32(s.from.Substring(0, 2)) &&
                                         Convert.ToInt32(scheduleModel.toDateAndTime.Substring(14, 2)) > Convert.ToInt32(s.from.Substring(3, 2)))
                                {
                                    scheduleModel.toDateAndTime = scheduleModel.fromDateAndTime.Substring(0, 11) + s.from + ":59";
                                }

                                else if (Convert.ToInt32(scheduleModel.toDateAndTime.Substring(11, 2)) > Convert.ToInt32(s.from.Substring(0, 2)))
                                {
                                    scheduleModel.toDateAndTime = scheduleModel.fromDateAndTime.Substring(0, 11) + s.from + ":59";
                                }
                            }
                        }
                    }
                }

                else if (scheduleModel.toDateAndTime == null)
                {
                    scheduleModel.toDateAndTime = scheduleModel.fromDateAndTime.Substring(0, 11) + "23:59:59";
                }
            }
            //Set toDateAndTime if null end ----------------------------------->

            //Get number of days
            int numberOfDays = (Convert.ToInt32(Math.Floor((DateTime.Parse(scheduleModel.toDateAndTime) - DateTime.Parse(scheduleModel.fromDateAndTime)).TotalDays)) + 1);

            //If more then one day but less then 100
            if (numberOfDays > 1 && numberOfDays < 100)
            {
                List <Schedule> schedules = new List <Schedule>();
                DateTime        startDay  = DateTime.Parse(scheduleModel.fromDateAndTime);
                for (int i = 0; i < numberOfDays - 1; i++)
                {
                    string date = startDay.AddDays(i).ToString().Substring(0, 10);
                    schedules.Add(new Schedule(scheduleModel.roomNr, date, "07:00", "23:59", scheduleModel.available));
                }

                foreach (Schedule s in schedules)
                {
                    updateSchedule(s, user);
                }

                schedules.Add(new Schedule(scheduleModel.roomNr, scheduleModel.toDateAndTime.Substring(0, 10), "07:00", scheduleModel.toDateAndTime.Substring(11, 5), scheduleModel.available));
                _taskRepository.Post(CustomMapper.MapTo.Task(schedules), username);

                return("");
            }

            //if only one day
            else if (numberOfDays == 1)
            {
                string to       = scheduleModel.toDateAndTime.Substring(11, 5);
                string fromDate = scheduleModel.fromDateAndTime.Substring(0, 10);
                string from     = scheduleModel.fromDateAndTime.Substring(11, 5);

                Schedule schedule = new Schedule(scheduleModel.roomNr, fromDate, from, to, scheduleModel.available);
                if (scheduleModel.scheduleInfo != null)
                {
                    schedule.moment = scheduleModel.scheduleInfo;
                }
                if (scheduleModel.course != null)
                {
                    schedule.course = scheduleModel.course;
                }
                updateSchedule(schedule, user);
                _taskRepository.Post(CustomMapper.MapTo.Task(schedule), username);
                return("");
            }

            return("Wrong input of date, numberOfDays may not be negative or larger then 100");
        }
Exemplo n.º 7
0
        /// <summary>
        /// Fills the message with values
        /// </summary>
        protected sealed override MessagesModel Fill()
        {
            var leaveMsg = GetLeaveMessage(MessageType);

            leaveMsg.Greeting = leaveMsg.Greeting.Replace(Receiver, "Manager (s)");

            TimeSpan leaveSpan    = (LeaveModel.LeaveDateEnd - LeaveModel.LeaveDateStart);
            var      leaveDays    = 0;
            var      leaveHours   = 0;
            var      leaveMinutes = 0;

            leaveDays    = leaveSpan.Days;
            leaveHours   = leaveSpan.Hours;
            leaveMinutes = leaveSpan.Minutes;
            if (leaveSpan.Hours >= 8)
            {
                leaveDays++;
                leaveHours = 0;
            }

            //get require hours
            using (var contextEf = new DataContextEF())
            {
                var staffHours = contextEf.StaffHourData.Where(x => x.StaffId.Equals(LeaveModel.StaffId)).ToList();
                #region

                //double requiredMinutes = 0;
                //double requiredHours = 0;


                //for (int i = 0; i < staffHours.Count; i++)
                //{
                //    if (staffHours[i].DayId == (int)DateTime.Now.DayOfWeek)
                //    {
                //        requiredHours = (staffHours[i].DayTimeEnd.TimeOfDay - staffHours[i].DayTimeStart.TimeOfDay).Hours;
                //        requiredMinutes = (staffHours[i].DayTimeEnd.TimeOfDay - staffHours[i].DayTimeStart.TimeOfDay).Minutes;
                //        break;
                //    }
                //}

                //if (leaveHours == requiredHours)
                //{
                //    leaveHours = 0;

                //    if (leaveDays == 0)
                //    {
                //        leaveDays = leaveDays + 1;

                //    }
                //    else if (leaveDays > 0)
                //    {
                //        leaveDays++;
                //    }
                //}

                #endregion
                leaveMsg.Body = leaveMsg.Body
                                .Replace(Applicant, LeaveModel.StaffMember.StaffFullName)
                                .Replace(Leavetype, EnumHelper.GetEnumDescriptions((LeaveType)LeaveModel.LeaveType))
                                .Replace(FromDate, LeaveModel.LeaveDateStart.ToLongDateString() + " " + LeaveModel.LeaveDateStart.TimeOfDay /*.Add(addToHours)*/)
                                .Replace(ToDate, LeaveModel.LeaveDateEnd.ToLongDateString() + " " + LeaveModel.LeaveDateEnd.TimeOfDay /*.Add(addToHours)*/)
                                .Replace(RequestDate, LeaveModel.LeaveRequestDate.ToShortDateString())
                                .Replace(Days, leaveDays +
                                         " Day(s), " + leaveHours
                                         + " Hour(s), " + leaveMinutes
                                         + " Minute(s) ")
                                .Replace(Comments, LeaveModel.LeaveComments)
                                .Replace(RedirectLink, "http://intranet/#/view_theleave/" + LeaveModel.LeaveId)
                                .Replace(OtherDetails, StaffModels.Any() ? BuildOtherDetails() : string.Empty);

                return(leaveMsg);
            }
        }
Exemplo n.º 8
0
        public async Task <HttpResponseMessage> SetStaff(StaffModels item)
        {
            Result    response = new Result();
            bool      ret      = false;
            DataSet   ds       = new DataSet();
            DataTable dt       = new DataTable();

            try
            {
                int iCount = repository.GetCheckUniqeLogin(
                    " Staffs ",
                    " StaffCode ",
                    " and StaffCode=" + repository.ReplaceString(item.StaffCode), "StaffID", item.StaffID);

                bool ExistOK = false;

                if (iCount > 0)
                {
                    ExistOK = true;
                }

                if (ExistOK)
                {
                    response.StatusCode = (int)StatusCodes.Error;
                    response.Messages   = "รหัสพนักงานซ้ำ";
                    //throw new Exception(" รหัสแผนก ซ้ำ !!!");
                }
                else
                {
                    iCount = repository.GetCheckUniqeLogin(
                        " Staffs ",
                        " StaffLogin ",
                        " and StaffLogin="******"StaffID", item.StaffID);

                    ExistOK = false;
                    if (iCount > 0)
                    {
                        ExistOK = true;
                    }

                    if (ExistOK)
                    {
                        response.StatusCode = (int)StatusCodes.Error;
                        response.Messages   = "รหัส User login ซ้ำ";
                        //throw new Exception(" รหัสแผนก ซ้ำ !!!");
                    }
                    else
                    {
                        ret = await repository.SetStaffData(item);

                        if (ret)
                        {
                            response.StatusCode = (int)StatusCodes.Succuss;
                            response.Messages   = "บันทึกข้อมูลเรียบร้อยแล้ว";
                        }
                        else
                        {
                            response.StatusCode = (int)StatusCodes.Error;
                            response.Messages   = "";
                        }
                    }
                }
            }
            catch (Exception e)
            {
                response.StatusCode = (int)StatusCodes.Error;
                response.Messages   = e.Message;
            }


            //response.Results = ds;
            //response.Records = ds.Tables[0].Rows.Count;
            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
Exemplo n.º 9
0
        public async Task <bool> SetStaffData(StaffModels item)
        {
            bool      result = false;
            string    strSQL = null;
            DataTable dt     = new DataTable();

            if (item.StaffID == 0)
            {
                strSQL = "Insert Into Staffs (StaffLogin,StaffPassword,StaffCode,StaffFirstName,StaffLastName,StaffPosition,StaffLevel,StaffDepartmentID,InputDate,UpdateDate) VALUES (@StaffLogin,@StaffPassword,@StaffCode,@StaffFirstName,@StaffLastName,@StaffPosition,@StaffLevel,@StaffDepartmentID,@InputDate,@UpdateDate)";
                List <SqlParameter> sp = new List <SqlParameter>()
                {
                    new SqlParameter()
                    {
                        ParameterName = "@StaffLogin", SqlDbType = SqlDbType.NVarChar, Value = item.StaffLogin
                    },
                    new SqlParameter()
                    {
                        ParameterName = "@StaffPassword", SqlDbType = SqlDbType.NVarChar, Value = Base64Encode(item.StaffPassword)
                    },
                    new SqlParameter()
                    {
                        ParameterName = "@StaffCode", SqlDbType = SqlDbType.NVarChar, Value = item.StaffCode.ToUpper()
                    },
                    new SqlParameter()
                    {
                        ParameterName = "@StaffFirstName", SqlDbType = SqlDbType.NVarChar, Value = DBString(item.StaffFirstName)
                    },
                    new SqlParameter()
                    {
                        ParameterName = "@StaffLastName", SqlDbType = SqlDbType.NVarChar, Value = DBString(item.StaffLastName)
                    },
                    new SqlParameter()
                    {
                        ParameterName = "@StaffPosition", SqlDbType = SqlDbType.NVarChar, Value = DBString(item.StaffPosition)
                    },
                    new SqlParameter()
                    {
                        ParameterName = "@StaffLevel", SqlDbType = SqlDbType.TinyInt, Value = item.StaffLevel
                    },
                    new SqlParameter()
                    {
                        ParameterName = "@StaffDepartmentID", SqlDbType = SqlDbType.Int, Value = item.StaffDepartmentID
                    },
                    new SqlParameter()
                    {
                        ParameterName = "@InputDate", SqlDbType = SqlDbType.DateTime, Value = DateTime.Now
                    },
                    new SqlParameter()
                    {
                        ParameterName = "@UpdateDate", SqlDbType = SqlDbType.DateTime, Value = DateTime.Now
                    }
                };
                DBHelper.Execute(strSQL, sp);
            }
            else
            {
                strSQL = "UPDATE Staffs SET StaffLogin=@StaffLogin,StaffPassword=@StaffPassword,StaffCode=@StaffCode,StaffFirstName=@StaffFirstName,StaffLastName=@StaffLastName,StaffPosition=@StaffPosition,StaffLevel=@StaffLevel,StaffDepartmentID=@StaffDepartmentID,UpdateDate=GETDATE() WHERE StaffID=@StaffID";

                List <SqlParameter> sp = new List <SqlParameter>()
                {
                    new SqlParameter()
                    {
                        ParameterName = "@StaffID", SqlDbType = SqlDbType.VarChar, Value = item.StaffID
                    },
                    new SqlParameter()
                    {
                        ParameterName = "@StaffLogin", SqlDbType = SqlDbType.NVarChar, Value = item.StaffLogin
                    },
                    new SqlParameter()
                    {
                        ParameterName = "@StaffPassword", SqlDbType = SqlDbType.NVarChar, Value = Base64Encode(item.StaffPassword)
                    },
                    new SqlParameter()
                    {
                        ParameterName = "@StaffCode", SqlDbType = SqlDbType.NVarChar, Value = item.StaffCode.ToUpper()
                    },
                    new SqlParameter()
                    {
                        ParameterName = "@StaffFirstName", SqlDbType = SqlDbType.NVarChar, Value = DBString(item.StaffFirstName)
                    },
                    new SqlParameter()
                    {
                        ParameterName = "@StaffLastName", SqlDbType = SqlDbType.NVarChar, Value = DBString(item.StaffLastName)
                    },
                    new SqlParameter()
                    {
                        ParameterName = "@StaffPosition", SqlDbType = SqlDbType.NVarChar, Value = DBString(item.StaffPosition)
                    },
                    new SqlParameter()
                    {
                        ParameterName = "@StaffLevel", SqlDbType = SqlDbType.TinyInt, Value = item.StaffLevel
                    },
                    new SqlParameter()
                    {
                        ParameterName = "@StaffDepartmentID", SqlDbType = SqlDbType.Int, Value = item.StaffDepartmentID
                    }
                };
                DBHelper.Execute(strSQL, sp);
            }
            return(true);
        }