Exemplo n.º 1
0
 public EmployeeScheduleModel GetEmployeesScheduleByJobId(int jobid)
 {
     //unitOfWork.StartTransaction();
     EmployeeScheduleRepository repo = new EmployeeScheduleRepository(unitOfWork);
     EmployeeScheduleModel employeeScheduleList = new EmployeeScheduleModel();
        EmployeeSchedule employeeSchedule = new EmployeeSchedule();
     AutoMapper.Mapper.Map(employeeScheduleList, employeeSchedule);
     employeeSchedule = repo.GetAll().Where(x => x.JobId == jobid).FirstOrDefault();
     //unitOfWork.Commit();
     AutoMapper.Mapper.Map(employeeSchedule, employeeScheduleList);
     return employeeScheduleList;
 }
Exemplo n.º 2
0
 public EmployeeScheduleModel SaveEmployeeSchedule(EmployeeScheduleModel model)
 {
     //unitOfWork.StartTransaction();
     EmployeeScheduleRepository repo = new EmployeeScheduleRepository(unitOfWork);
     EmployeeSchedule employeeSchedule = new EmployeeSchedule();
     AutoMapper.Mapper.Map(model, employeeSchedule);
     repo.Insert(employeeSchedule);
     //unitOfWork.Commit();
     AutoMapper.Mapper.Map(employeeSchedule, model);
     return model;
 }
Exemplo n.º 3
0
 public EmployeeScheduleModel UpdateEmployeeSchedule(EmployeeScheduleModel model)
 {
     //unitOfWork.StartTransaction();
     EmployeeScheduleRepository repo = new EmployeeScheduleRepository(unitOfWork);
     EmployeeSchedule employeeSchedule = new EmployeeSchedule();
     employeeSchedule = repo.GetAll().Where(x => x.Id == model.Id).FirstOrDefault();
     AutoMapper.Mapper.Map(model, employeeSchedule);
     repo.Update(employeeSchedule);
     //unitOfWork.Commit();
     AutoMapper.Mapper.Map(employeeSchedule, model);
     return model;
 }
Exemplo n.º 4
0
 public IHttpActionResult UpdatescheduleForEmployee(EmployeeScheduleBindingModel model)
 {
     try
     {
         EmployeeScheduleModel employeeScheduleModel = new EmployeeScheduleModel();
         AutoMapper.Mapper.Map(model, employeeScheduleModel);
         employeeScheduleModel = employeeScheduleService.UpdateEmployeeSchedule(employeeScheduleModel);
         AutoMapper.Mapper.Map(employeeScheduleModel, model);
         return Ok(model);
     }
     catch (Exception ex)
     {
         Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
         return BadRequest(ex.Message);
     }
 }
Exemplo n.º 5
0
        public IHttpActionResult Cancel(string employeeId, int jobId)
        {
            try
            {

                EmployeeScheduleModel employeeScheduleModel = new EmployeeScheduleModel();
                employeeScheduleModel = employeeScheduleService.GetEmployeesScheduleByEmployeeId(employeeId).FirstOrDefault();
                employeeScheduleService.DeleteEmployeeSchedule(employeeScheduleModel.Id);
                return Ok("Cancel");
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                return BadRequest(ex.Message);
            }
        }
Exemplo n.º 6
0
 public IHttpActionResult addscheduleForEmployee(EmployeeScheduleBindingModel model)
 {
     try
     {
         EmployeeScheduleModel employeeScheduleModel = new EmployeeScheduleModel();
         AutoMapper.Mapper.Map(model, employeeScheduleModel);
         employeeScheduleModel = employeeScheduleService.SaveEmployeeSchedule(employeeScheduleModel);
         AutoMapper.Mapper.Map(employeeScheduleModel, model);
         ////Get job by jobId
         //JobModel jobModel = new JobModel();
         //jobModel = jobService.GetJobById(model.JobId);
         //jobModel.EmployeeId = model.EmployeeId;
         //jobModel = jobService.UpadteJob(jobModel);
         //ApplicationUser user = UserManager.FindById(model.EmployeeId);
         //if (user != null)
         //{
         //    if (user.DeviceType == Utility.Constants.DEVICE_TYPE_ANDROID)
         //    {
         //        var response = sendNotificationService.SendNotificationForAndroid(user.DeviceToken, "This is your new task");
         //    }
         //    else if (user.DeviceType == Utility.Constants.DEVICE_TYPE_IOS)
         //    {
         //        sendNotificationService.SendNotificationForIOS(user.DeviceToken, "This is your new task");
         //    }
         //}
         return Ok(model);
     }
     catch (Exception ex)
     {
         Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
         return BadRequest(ex.Message);
     }
 }
Exemplo n.º 7
0
        public IHttpActionResult GetEmployeeByServiceProviderId(string id, int jobId)
        {
            //get service provider employee mapping 
            List<ServiceProviderEmployeeMappingModel> serviceProviderEmployeeMappingModel = new List<ServiceProviderEmployeeMappingModel>();
            serviceProviderEmployeeMappingModel = serviceProviderEmployeeMappingService.GetEmployeeByServiceProviderId(id);
            //Get employee
            List<EmployeeModel> employeeModel = new List<EmployeeModel>();
            List<EmployeeBindingModel> employeeBindingModel = new List<EmployeeBindingModel>();
            string[] employeeId = serviceProviderEmployeeMappingModel.Select(u => u.EmployeeId.ToString()).ToArray();
            employeeModel = employeeService.GetEmployeeListByServiceProviderId(employeeId);
            AutoMapper.Mapper.Map(employeeModel, employeeBindingModel);
            //get job according to employee
            JobModel jobModel = new JobModel();
            foreach (var item in employeeBindingModel)
            {
                jobModel = jobService.GetJobById(jobId);
                //int count = jobModel.Where(x => JobStatus.Current.ToString().Contains(x.Status.ToString())).Count(); //jobService.GetStatusOfEmployee();
                EmployeeScheduleModel employeeScheduleModel = new EmployeeScheduleModel();
                employeeScheduleModel = employeeScheduleService.GetEmployeesScheduleByEmployeeId(item.EmployeeId).FirstOrDefault();
                JobModel assignedJobModel = new JobModel();
                if (employeeScheduleModel != null)
                {
                    assignedJobModel = jobService.GetJobById(employeeScheduleModel.JobId);
                }

                if (employeeScheduleModel != null)
                {
                    if (jobModel.StartDate > employeeScheduleModel.Start)
                    {
                        if (employeeScheduleModel.Start < jobModel.StartDate && employeeScheduleModel.End > jobModel.StartDate)
                        {
                            //if (assignedJobModel.Status == JobStatus.Current)
                            //{
                            //    item.EmployeeStatus = EmployeeStatus.Working;
                            //}
                            //else
                            //{
                            //    item.EmployeeStatus = EmployeeStatus.Available;
                            //}
                            item.EmployeeStatus = EmployeeStatus.Working;
                        }
                        else
                        {
                            item.EmployeeStatus = EmployeeStatus.Available;
                        }
                    }
                    else
                    {
                        TimeSpan duration = Convert.ToDateTime(employeeScheduleModel.Start) - Convert.ToDateTime(jobModel.StartDate);
                        jobModel.StartDate = Convert.ToDateTime(jobModel.StartDate).AddHours(duration.Hours).AddMinutes(duration.Minutes);
                        if (employeeScheduleModel.Start <= jobModel.StartDate && employeeScheduleModel.Start <= jobModel.EndDate)
                        {
                            //if (assignedJobModel.Status == JobStatus.Current)
                            //{
                            //    item.EmployeeStatus = EmployeeStatus.Working;
                            //}
                            //else
                            //{
                            //    item.EmployeeStatus = EmployeeStatus.Available;
                            //}
                            item.EmployeeStatus = EmployeeStatus.Working;
                        }
                        else
                        {
                            item.EmployeeStatus = EmployeeStatus.Available;
                        }
                    }
                    //if (jobModel.StartDate != employeeScheduleModel.Start && jobModel.EndDate != employeeScheduleModel.End)
                    //{
                    //    item.EmployeeStatus = EmployeeStatus.Available;
                    //}
                    //else
                    //{
                    //    item.EmployeeStatus = EmployeeStatus.Working;
                    //}
                }
                else
                {
                    item.EmployeeStatus = EmployeeStatus.Available;
                }



            }


            return Ok(employeeBindingModel);
        }
Exemplo n.º 8
0
        public IHttpActionResult CompleteTask(string userId, int jobId)
        {
            JobBindingModel jobBindingModel = new JobBindingModel();
            try
            {
                
                //Get job by jobId
                JobModel jobModel = new JobModel();
                AutoMapper.Mapper.Map(jobBindingModel, jobModel);
                jobModel = jobService.GetJobById(jobId);
                jobModel.Status = JobStatus.Completed;
                jobModel = jobService.UpadteJob(jobModel);
                AutoMapper.Mapper.Map(jobModel, jobBindingModel);
                //Get employee schedule by jobid and delete
                EmployeeScheduleModel employeeScheduleModel = new EmployeeScheduleModel();
                employeeScheduleModel = employeeScheduleService.GetEmployeesScheduleByJobId(jobId);
                employeeScheduleService.DeleteEmployeeSchedule(employeeScheduleModel.Id);
                ApplicationUser user = UserManager.FindById(jobModel.ClientId);
                if (user != null)
                {
                    if (user.DeviceType == Utility.Constants.DEVICE_TYPE_ANDROID)
                    {
                        string postData = "collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.userId=" + userId + "&data.jobId=" + jobId + "&data.type=" + Utility.Constants.JOB_COMPLETED_TYPE + "&data.message=" + Utility.Constants.MESSAGE_FOR_JOB_COMPLETED + "&data.time=" + System.DateTime.Now.ToString() + "&registration_id=" + user.DeviceToken + "";
                        var response = sendNotificationService.SendNotificationForAndroid(postData);
                    }
                    else
                    {
                        string payload = "{\"aps\":{\"alert\":\"" + "Hi, " + Utility.Constants.MESSAGE_FOR_JOB_COMPLETED + "" + "\",\"badge\":1,\"sound\":\"default\"},\"JobId\":" + jobId + ",\"userId\":\"" + userId + "\",\"type\":\"" + Utility.Constants.JOB_COMPLETED_TYPE + "\"}";
                        sendNotificationService.SendNotificationForIOS(user.DeviceToken, payload);
                    }
                }

            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                return BadRequest(ex.Message);
            }
            return Json(jobBindingModel);
        }