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)); } }
/// <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; } }