示例#1
0
 public EmployeeModel GetEmployeeById(string employeeId)
 {
     //unitOfWork.StartTransaction();
     EmployeeRepository repo = new EmployeeRepository(unitOfWork);
     EmployeeModel employeeModel = new EmployeeModel();
     Employee employee = new Employee();
     AutoMapper.Mapper.Map(employeeModel, employee);
     Dispose(true);
     employee = repo.GetAll().Where(x => x.EmployeeId == employeeId).FirstOrDefault();
     //unitOfWork.Commit();
     AutoMapper.Mapper.Map(employee, employeeModel);
     return employeeModel;
 }
示例#2
0
        public async Task<IHttpActionResult> UpdateServiceProviderAsIndividual()
        {

            try
            {
                //var userAgent = HttpContext.Current.Request.UserAgent;
                //var deviceType = HttpContext.Current.Request.Headers.GetValues("device_type");
                if (!Request.Content.IsMimeMultipartContent())
                {
                    throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
                }

                var root = HttpContext.Current.Server.MapPath(Utility.Constants.BASE_FILE_UPLOAD_PATH);
                Directory.CreateDirectory(root);
                var provider = new MultipartFormDataStreamProvider(root);
                var resultModel = await Request.Content.ReadAsMultipartAsync(provider);
                if (resultModel.FormData["model"] == null)
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }
                var result = resultModel.FormData["model"];
                EmployeeBindingModel employeeBindingModel = new EmployeeBindingModel();
                //var model = result.Substring(1, result.Length - 2);
                employeeBindingModel = JsonConvert.DeserializeObject<EmployeeBindingModel>(result);
                //AutoMapper.Mapper.Map(employeeBindingModel, clientModel);
                //var count = resultModel.FormData.Count;

                //employeeBindingModel.EmployeeId = resultModel.FormData[0];
                //employeeBindingModel.FirstName = resultModel.FormData[1];
                //employeeBindingModel.LastName = resultModel.FormData[2];
                //employeeBindingModel.Description = resultModel.FormData[3];
                //employeeBindingModel.CityId = Convert.ToInt32(resultModel.FormData[4]);
                //employeeBindingModel.DistrictId = Convert.ToInt32(resultModel.FormData[5]);
                //employeeBindingModel.CarTypeId = Convert.ToInt32(resultModel.FormData[6]);
                //employeeBindingModel.LicensePlateNumber = resultModel.FormData[7];

                if (!ModelState.IsValid)
                {
                    return BadRequest(ModelState);
                }

                else
                {
                    try
                    {
                        EmployeeModel employeeModelForCheckRecord = new EmployeeModel();
                        employeeModelForCheckRecord = employeeService.GetEmployeeById(employeeBindingModel.EmployeeId);

                        if (resultModel.FileData.Count > 0)
                        {
                            string fileName;

                            if (HttpContext.Current.Request.Files != null)
                            {
                                for (var i = 0; i < resultModel.FileData.Count; i++)
                                {
                                    var file = HttpContext.Current.Request.Files[i];
                                    fileName = file.FileName;


                                    if (i == 0)
                                    {

                                        file.SaveAs(Path.Combine(root, Utility.Constants.EMPLOYEE_PROFILE_PATH, fileName));
                                        employeeBindingModel.ProfileImage = fileName;
                                    }
                                    else
                                    {
                                        file.SaveAs(Path.Combine(root, Utility.Constants.NATIONAL_ID_PATH, fileName));
                                        employeeBindingModel.NationalIdAndIqamaNumber = fileName;
                                    }

                                }

                            }


                        }
                        if (employeeBindingModel.ProfileImage == null)
                        {
                            employeeBindingModel.ProfileImage = employeeModelForCheckRecord.ProfileImage;
                        }
                        if (employeeBindingModel.NationalIdAndIqamaNumber == null)
                        {
                            employeeBindingModel.NationalIdAndIqamaNumber = employeeModelForCheckRecord.NationalIdAndIqamaNumber;
                        }

                        //Update employee
                        EmployeeModel employeeModelEntity = new EmployeeModel();
                        AutoMapper.Mapper.Map(employeeBindingModel, employeeModelEntity);
                        employeeModelEntity = employeeService.UpadteEmployee(employeeModelEntity);
                        AutoMapper.Mapper.Map(employeeModelEntity, employeeBindingModel);
                        //Add Car type for Employee
                        CarEmployeeMappingModel carEmployeeMappingModel = new CarEmployeeMappingModel();
                        carEmployeeMappingModel.CarTypeId = employeeBindingModel.CarTypeId;
                        carEmployeeMappingModel.EmployeeId = employeeBindingModel.EmployeeId;
                        carEmployeeMappingModel = carEmployeeMappingService.SaveCarEmployeeMapping(carEmployeeMappingModel);
                        //save location for employee

                        UserLocationModel locationModel = new UserLocationModel();
                        locationModel.UserId = employeeBindingModel.EmployeeId;
                        locationModel.CityId = employeeBindingModel.CityId;
                        locationModel.DistrictId = 1;
                        userLocationService.InsertUserLocation(locationModel);
                        //locationModel = userLocationService.FindLocationById(employeeBindingModel.EmployeeId);
                        //if (locationModel.UserLocationId != 0)
                        //{
                        //    userLocationService.UpadteUserLocation(locationModel);
                        //}


                        var user = await UserManager.FindByIdAsync(employeeBindingModel.EmployeeId);
                        if (user.Email != employeeBindingModel.Email)
                        {
                            IdentityResult userResult = await UserManager.UpdateAsync(user);
                        }
                    }
                    catch (Exception ex)
                    {
                        Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                        return BadRequest(ex.Message);
                    }

                }

                return Json(employeeBindingModel);
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                return BadRequest(ex.Message);
            }
        }
示例#3
0
        public async Task<IHttpActionResult> RegisterServiceProviderAsIndividual(EmployeeBindingModel employeeModel)
        {
            //using (var dataContext = new URFXDbContext())
            //{
            //    TransactionScope transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled);
            //    {
            try
            {
                if (!ModelState.IsValid)
                {
                    return BadRequest(ModelState);
                }

                var user = new ApplicationUser() { UserName = employeeModel.Email, Email = employeeModel.Email, PhoneNumber = employeeModel.PhoneNumber, DeviceType = employeeModel.DeviceType, DeviceToken = employeeModel.DeviceToken };

                IdentityResult result = await UserManager.CreateAsync(user, employeeModel.Password);

                if (!result.Succeeded)
                {
                    //  transaction.Dispose();
                    ////UserManager.Delete(user);
                    return GetErrorResult(result);
                }

                else
                {
                    IdentityResult resultRoleCreated = await UserManager.AddToRoleAsync(user.Id, URFXRoles.ServiceProvider.ToString());
                    if (!resultRoleCreated.Succeeded)
                    {
                        //  transaction.Dispose();
                        //UserManager.Delete(user);
                        return GetErrorResult(resultRoleCreated);
                    }
                    else
                    {
                        try
                        {
                            //save service provider
                            RegisterServiceProviderBindingModel serviceProviderBindingModel = new RegisterServiceProviderBindingModel();
                            ServiceProviderModel serviceProviderModel = new ServiceProviderModel();

                            serviceProviderBindingModel.ServiceProviderId = user.Id;
                            serviceProviderBindingModel.StartDate = DateTime.UtcNow;
                            serviceProviderBindingModel.CompanyName = employeeModel.FirstName + " " + employeeModel.LastName;
                            serviceProviderBindingModel.Description = employeeModel.Description;
                            serviceProviderBindingModel.GeneralManagerName = employeeModel.FirstName + " " + employeeModel.LastName;
                            serviceProviderBindingModel.ServiceProviderType = ServiceProviderType.Individual;
                            AutoMapper.Mapper.Map(serviceProviderBindingModel, serviceProviderModel);
                            serviceProviderModel = serviceProviderService.SaveServiceProvider(serviceProviderModel);

                            employeeModel.EmployeeId = user.Id;
                            EmployeeModel employeeModelEntity = new EmployeeModel();
                            AutoMapper.Mapper.Map(employeeModel, employeeModelEntity);
                            employeeModelEntity = employeeService.SaveEmployee(employeeModelEntity);
                            AutoMapper.Mapper.Map(employeeModelEntity, employeeModel);



                            //ServiceProviderEmployee Mapping
                            ServiceProviderEmployeeMappingModel serviceProviderEmployeeMappingModel = new ServiceProviderEmployeeMappingModel();
                            serviceProviderEmployeeMappingModel.EmployeeId = employeeModel.EmployeeId;
                            if (employeeModel.ServiceProviderId != null)
                            {
                                serviceProviderEmployeeMappingModel.ServiceProviderId = employeeModel.ServiceProviderId;
                            }
                            else
                            {
                                serviceProviderEmployeeMappingModel.ServiceProviderId = employeeModel.EmployeeId;
                            }
                            serviceProviderEmployeeMappingModel = serviceProviderEmployeeMappingService.SaveEmployeeAccordingToServiceProvider(serviceProviderEmployeeMappingModel);
                            //send email
                            var Subject = Utility.Constants.CONFIRMATION_SUBJECT;
                            var code = UserManager.GenerateEmailConfirmationToken(user.Id);
                            var scheme = HttpContext.Current.Request.Url.Scheme;
                            var host = HttpContext.Current.Request.Url.Host;
                            var port = HttpContext.Current.Request.Url.Port;
                            string language = "en";
                            var cookie = HttpContext.Current.Request.Cookies.Get("APPLICATION_LANGUAGE");
                            if (cookie != null)
                                language = cookie.Value;
                            string exactPath;
                            if (language == "en")
                            {
#if DEBUG
                                exactPath = scheme + "://" + host + port + "/Content/URFXTheme/images/logo.png";
#else
                                exactPath = scheme + "://" + host + "/Content/URFXTheme/images/logo.png";
#endif
                            }
                            else
                            {
#if DEBUG

                                exactPath = scheme + "://" + host + port + "/Content/URFXTheme/images/arabic-logo.png";
#else
                                exactPath = scheme + "://" + host + "/Content/URFXTheme/images/arabic-logo.png";
#endif

                            }
#if DEBUG
                            var link = scheme + "://" + host + port + "/App/#/confirmemail/" + user.Id + "";
#else
                            var link = scheme + "://" + host + "/#/confirmemail/" + user.Id + "";
#endif

                            var Link = "<a href='" + link + "'>" + link + "</a>";
                            string text = System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath(Utility.Constants.CONFIRMATION_EMAIL_PATH));
                            String Body = "";
                            Body = String.Format(text, user.UserName, Link, exactPath);
                            try
                            {
                                // await service.SendAsync(message);
                                await UserManager.SendEmailAsync(user.Id, Subject, Body);
                            }
                            catch (Exception ex)
                            {
                                //  transaction.Dispose();
                                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                                return BadRequest(ex.Message);
                            }
                            //transaction.Complete();
                        }
                        catch (Exception ex)
                        {
                            // transaction.Dispose();
                            Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                            return BadRequest(ex.Message);
                        }
                    }
                }
                return Json(employeeModel);
                // return Ok("{\"response\":" + Json(employeeModel) + "}");
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                return BadRequest(ex.Message);
            }

            //    }
            //}

        }
示例#4
0
        public IHttpActionResult DeleteEmployee(string id)
        {
            try
            {
                EmployeeModel employeeModel = new EmployeeModel();
                if (employeeModel == null)
                {
                    return NotFound();
                }
                List<UserLocationModel> model = new List<UserLocationModel>();
                model = userLocationService.FindLocationListById(id);
                foreach (var item in model)
                {
                    userLocationService.DeleteUserLocation(item.UserLocationId);
                }

                serviceProviderEmployeeMappingService.DeleteServiceProviderEmployeeMapping(id);
                //delete Car Type of employee
                List<CarEmployeeMappingModel> carEmployeeMappingModel = new List<CarEmployeeMappingModel>();
                carEmployeeMappingModel = carEmployeeMappingService.GetCarEmployeeMappingListByEmployeeId(id);
                carEmployeeMappingModel.ForEach(x =>
                {
                    carEmployeeMappingService.DeleteCarEmployeeMapping(x.CarEmployeeMappingId);
                });

                employeeService.DeleteEmployee(id);
                ServiceProviderModel serviceProvider = new ServiceProviderModel();
                serviceProvider = serviceProviderService.GetServiceProviderById(id);
                if (serviceProvider.ServiceProviderId != null)
                {

                    //delete service provider service mapping
                    List<ServiceProviderServiceMappingModel> serviceProviderMappingModel = new List<ServiceProviderServiceMappingModel>();
                    serviceProviderMappingModel = serviceProviderServiceMappingService.FindServiceByUserId(id);
                    foreach (var item in serviceProviderMappingModel)
                    {
                        serviceProviderServiceMappingService.DeleteServiceProviderServiceMapping(item.Id);
                    }
                    //Delete service provider employee mapping
                    List<ServiceProviderEmployeeMappingModel> serviceProviderEmployeeMappingModel = new List<ServiceProviderEmployeeMappingModel>();
                    serviceProviderEmployeeMappingModel = serviceProviderEmployeeMappingService.GetEmployeeByServiceProviderId(id);
                    foreach (var item in serviceProviderEmployeeMappingModel)
                    {
                        serviceProviderEmployeeMappingService.DeleteServiceProviderEmployeeMapping(item.EmployeeId);
                    }
                    //Delete service provider
                    serviceProviderService.DeleteServiceProvider(id);

                }
                ApplicationUser user = UserManager.FindById(id);

                IdentityResult result = UserManager.Delete(user);
                if (!result.Succeeded)
                {
                    return GetErrorResult(result);
                }
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                return BadRequest(ex.Message);
            }
            return Ok();
        }
示例#5
0
        public async Task<IHttpActionResult> PostEmployee()
        {
            try
            {
                if (!Request.Content.IsMimeMultipartContent())
                {
                    throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
                }

                var root = HttpContext.Current.Server.MapPath(Utility.Constants.BASE_FILE_UPLOAD_PATH);
                Directory.CreateDirectory(root);
                var provider = new MultipartFormDataStreamProvider(root);
                var resultModel = await Request.Content.ReadAsMultipartAsync(provider);
                if (resultModel.FormData["model"] == null)
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }

                var model = resultModel.FormData["model"];
                EmployeeBindingModel employeeModel = new EmployeeBindingModel();
                employeeModel = JsonConvert.DeserializeObject<EmployeeBindingModel>(model);

                if (!ModelState.IsValid)
                {
                    return BadRequest(ModelState);
                }

                var user = new ApplicationUser() { UserName = employeeModel.Email, Email = employeeModel.Email, PhoneNumber = employeeModel.PhoneNumber, DeviceType = employeeModel.DeviceType, DeviceToken = employeeModel.DeviceToken };

                IdentityResult result = await UserManager.CreateAsync(user, employeeModel.Password);

                if (!result.Succeeded)
                {
                    //UserManager.Delete(user);
                    return GetErrorResult(result);
                }

                else
                {

                    IdentityResult resultRoleCreated = await UserManager.AddToRoleAsync(user.Id, URFXRoles.Employee.ToString());
                    if (!resultRoleCreated.Succeeded)
                    {
                        //UserManager.Delete(user);
                        return GetErrorResult(resultRoleCreated);
                    }
                    else
                    {
                        try
                        {
                            //Save employee
                            employeeModel.EmployeeId = user.Id;
                            EmployeeModel employeeModelEntity = new EmployeeModel();
                            AutoMapper.Mapper.Map(employeeModel, employeeModelEntity);
                            employeeModelEntity = employeeService.SaveEmployee(employeeModelEntity);
                            AutoMapper.Mapper.Map(employeeModelEntity, employeeModel);
                            //ServiceProviderEmployee Mapping
                            ServiceProviderEmployeeMappingModel serviceProviderEmployeeMappingModel = new ServiceProviderEmployeeMappingModel();
                            serviceProviderEmployeeMappingModel.EmployeeId = employeeModel.EmployeeId;
                            if (employeeModel.ServiceProviderId != null)
                            {
                                serviceProviderEmployeeMappingModel.ServiceProviderId = employeeModel.ServiceProviderId;
                            }
                            else
                            {
                                serviceProviderEmployeeMappingModel.ServiceProviderId = User.Identity.GetUserId();
                            }
                            ServiceProviderModel serviceProviderModel = serviceProviderService.GetServiceProviderById(serviceProviderEmployeeMappingModel.ServiceProviderId);
                            if (serviceProviderModel.CompanyName != null)
                                serviceProviderEmployeeMappingModel = serviceProviderEmployeeMappingService.SaveEmployeeAccordingToServiceProvider(serviceProviderEmployeeMappingModel);
                            var Subject = Utility.Constants.CONFIRMATION_SUBJECT;
                            var code = UserManager.GenerateEmailConfirmationToken(user.Id);
                            var scheme = HttpContext.Current.Request.Url.Scheme;
                            var host = HttpContext.Current.Request.Url.Host;
                            var port = HttpContext.Current.Request.Url.Port;
                            //var link = scheme + "//" + host + port + "/#/confirmemail";
                            //var Link = "<a href='" + link + "/" + user.Id + "'></a>";
                            string language = "en";
                            var cookie = HttpContext.Current.Request.Cookies.Get("APPLICATION_LANGUAGE");
                            if (cookie != null)
                                language = cookie.Value;
                            string exactPath;
                            if (language == "en")
                            {
                                // exactPath = scheme + "://" + host + port + "/Content/URFXTheme/images/logo.png";
                                exactPath = scheme + "://" + host + "/Content/URFXTheme/images/logo.png";
                            }
                            else
                            {
                                //exactPath = scheme + "://" + host + port + "/Content/URFXTheme/images/arabic-logo.png";
                                exactPath = scheme + "://" + host + "/Content/URFXTheme/images/arabic-logo.png";
                            }
                            string text = System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath(Utility.Constants.EMPLOYEE_USERNAME_PASSWORD_PATH));
                            String Body = "";
                            Body = String.Format(text, user.UserName, employeeModel.Password, exactPath);
                            try
                            {
                                // await service.SendAsync(message);
                                await UserManager.SendEmailAsync(user.Id, Subject, Body);
                            }
                            catch (Exception ex)
                            {

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


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



        }
示例#6
0
        public async Task<IHttpActionResult> PutEmployee()
        {

            try
            {
                if (!Request.Content.IsMimeMultipartContent())
                {
                    throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
                }

                var root = HttpContext.Current.Server.MapPath(Utility.Constants.BASE_FILE_UPLOAD_PATH);
                Directory.CreateDirectory(root);
                var provider = new MultipartFormDataStreamProvider(root);
                var resultModel = await Request.Content.ReadAsMultipartAsync(provider);
                if (resultModel.FormData["model"] == null)
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }
                var model = resultModel.FormData["model"];

                EmployeeBindingModel employeeBindingModel = new EmployeeBindingModel();
                employeeBindingModel = JsonConvert.DeserializeObject<EmployeeBindingModel>(model);

                if (!ModelState.IsValid)
                {
                    return BadRequest(ModelState);
                }

                else
                {

                    EmployeeModel employeeModelForCheckRecord = new EmployeeModel();
                    employeeModelForCheckRecord = employeeService.GetEmployeeById(employeeBindingModel.EmployeeId);

                    if (resultModel.FileData.Count > 0)
                    {
                        string fileName;

                        if (HttpContext.Current.Request.Files != null)
                        {
                            for (var i = 0; i < resultModel.FileData.Count; i++)
                            {
                                var file = HttpContext.Current.Request.Files[i];
                                fileName = file.FileName;


                                if (i == 0)
                                {

                                    file.SaveAs(Path.Combine(root, Utility.Constants.EMPLOYEE_PROFILE_PATH, fileName));
                                    employeeBindingModel.ProfileImage = fileName;
                                }
                                else
                                {
                                    file.SaveAs(Path.Combine(root, Utility.Constants.NATIONAL_ID_PATH, fileName));
                                    employeeBindingModel.NationalIdAndIqamaNumber = fileName;
                                }

                            }

                        }


                    }
                    if (employeeBindingModel.ProfileImage == null)
                    {
                        employeeBindingModel.ProfileImage = employeeModelForCheckRecord.ProfileImage;
                    }
                    if (employeeBindingModel.NationalIdAndIqamaNumber == null)
                    {
                        employeeBindingModel.NationalIdAndIqamaNumber = employeeModelForCheckRecord.NationalIdAndIqamaNumber;
                    }
                    //if (employeeBindingModel.IqamaNumber == null)
                    //{
                    //    employeeBindingModel.IqamaNumber = employeeModelForCheckRecord.IqamaNumber;
                    //}
                    try
                    {
                        //Update employee
                        EmployeeModel employeeModelEntity = new EmployeeModel();
                        AutoMapper.Mapper.Map(employeeBindingModel, employeeModelEntity);
                        employeeModelEntity = employeeService.UpadteEmployee(employeeModelEntity);
                        AutoMapper.Mapper.Map(employeeModelEntity, employeeBindingModel);
                        //Add Car type for Employee
                        if (employeeBindingModel.CarTypeId != 0)
                        {
                            CarEmployeeMappingModel carEmployeeMappingModel = new CarEmployeeMappingModel();
                            carEmployeeMappingModel.CarTypeId = employeeBindingModel.CarTypeId;
                            carEmployeeMappingModel.EmployeeId = employeeBindingModel.EmployeeId;
                            CarEmployeeMappingModel carEmployeeMappingModelCheck = new CarEmployeeMappingModel();
                            carEmployeeMappingModelCheck = carEmployeeMappingService.GetCarEmployeeMappingByEmployeeId(carEmployeeMappingModel.EmployeeId);
                            carEmployeeMappingModelCheck.CarTypeId = employeeBindingModel.CarTypeId;
                            carEmployeeMappingModelCheck.EmployeeId = employeeBindingModel.EmployeeId;
                            if (carEmployeeMappingModelCheck.CarEmployeeMappingId == 0)
                            {
                                carEmployeeMappingModel = carEmployeeMappingService.SaveCarEmployeeMapping(carEmployeeMappingModelCheck);
                            }
                            else
                            {
                                carEmployeeMappingModel = carEmployeeMappingService.UpadteCarEmployeeMapping(carEmployeeMappingModelCheck);
                            }
                        }


                        //save location for employee
                        var location = resultModel.FormData["LocationModel"];
                        UserLocationModel locationModel = new UserLocationModel();
                        UserLocationModel userlocationModel = new UserLocationModel();
                        locationModel = JsonConvert.DeserializeObject<UserLocationModel>(location);
                        locationModel.UserId = employeeBindingModel.EmployeeId;
                        locationModel.DistrictId = 1;
                        bool Exists;
                        Exists = userLocationService.CheckExistance(locationModel.UserId);
                        if (!Exists && locationModel.CityId != 0)
                        {
                            userLocationService.InsertUserLocation(locationModel);
                        }
                        else if (Exists)
                        {
                            userlocationModel = userLocationService.FindLocationById(locationModel.UserId);
                            locationModel.UserLocationId = userlocationModel.UserLocationId;
                            userLocationService.UpadteUserLocation(locationModel);
                        }
                        //check service provider as individual and update service provider
                        IndividualBindingModel individualBindingModel = new IndividualBindingModel();
                        RegisterServiceProviderBindingModel serviceProviderBindingModel = new RegisterServiceProviderBindingModel();
                        ServiceProviderModel serviceProvider = new ServiceProviderModel();
                        serviceProvider = serviceProviderService.GetServiceProviderById(employeeBindingModel.EmployeeId);
                        if (serviceProvider != null && serviceProvider.ServiceProviderType == ServiceProviderType.Individual)
                        {

                            serviceProvider.CompanyLogoPath = employeeBindingModel.ProfileImage;
                            serviceProvider.RegistrationCertificatePath = employeeBindingModel.NationalIdAndIqamaNumber;
                            serviceProvider.Description = employeeBindingModel.Description;

                            serviceProvider = serviceProviderService.UpadteServiceProvider(serviceProvider);
                        }
                        var user = await UserManager.FindByIdAsync(employeeBindingModel.EmployeeId);
                        if (user != null)
                        {
                            if (user.Email != employeeBindingModel.Email || user.PhoneNumber != employeeBindingModel.PhoneNumber)
                            {
                                user.Email = employeeBindingModel.Email;
                                user.PhoneNumber = employeeBindingModel.PhoneNumber;
                                IdentityResult result = await UserManager.UpdateAsync(user);
                            }
                        }

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

                }

                return Ok();
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                return BadRequest(ex.Message);
            }
        }
示例#7
0
        public IHttpActionResult UpdateQuickBlox(string userId, string quickBloxId)
        {
            try
            {
                EmployeeModel employeeModel = new EmployeeModel();
                employeeModel = employeeService.GetEmployeeById(userId);
                employeeModel.QuickBloxID = quickBloxId;
                employeeModel.Registred = true;
                employeeModel = employeeService.UpadteEmployee(employeeModel);
                return Json(employeeModel);
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                return BadRequest(ex.Message);
            }

        }
示例#8
0
 public IHttpActionResult GetEmployee(string id)
 {
     //Get employee
     EmployeeModel employeeModel = new EmployeeModel();
     EmployeeBindingModel employeeBindingModel = new EmployeeBindingModel();
     List<JobModel> jobModel = new List<JobModel>();
     List<JobBindingModel> jobBindingModel = new List<JobBindingModel>();
     employeeModel = employeeService.GetEmployeeById(id);
     AutoMapper.Mapper.Map(employeeModel, employeeBindingModel);
     //Get Details of employee from user table
     var Email = UserManager.FindById(id) != null ? UserManager.FindById(id).Email : "";
     var PhoneNumber = UserManager.FindById(id) != null ? UserManager.FindById(id).PhoneNumber : "";
     //Get Car Type of employee
     CarEmployeeMappingModel carEmployeeMappingModel = new CarEmployeeMappingModel();
     carEmployeeMappingModel = carEmployeeMappingService.GetCarEmployeeMappingByEmployeeId(id);
     //Get Location of employee
     userLocationModel = userLocationService.FindLocationById(id);
     employeeBindingModel.UserLocationModel = userLocationModel;
     employeeBindingModel.CarTypeId = carEmployeeMappingModel.CarTypeId;
     employeeBindingModel.Email = Email;
     employeeBindingModel.PhoneNumber = PhoneNumber;
     //Get rating for employee
     jobModel = jobService.GetJobListByEmployeeId(id);
     AutoMapper.Mapper.Map(jobModel, jobBindingModel);
     List<RatingModel> ratingModel = new List<RatingModel>();
     ratingModel = ratingService.GetAllRatings();
     jobBindingModel.ForEach(x =>
     {
         x.RatingModel = ratingModel.Where(j => j.JobId == x.JobId).ToList();
     });
     employeeBindingModel.JobBindingModel = jobBindingModel;
     var serviceProvider = serviceProviderService.GetServiceProviderById(id);
     if (serviceProvider != null)
     {
         employeeBindingModel.model = serviceProvider;
     }
     return Json(employeeBindingModel);
 }
示例#9
0
 public EmployeeModel UpadteEmployee(EmployeeModel model)
 {
     //unitOfWork.StartTransaction();
     EmployeeRepository repo = new EmployeeRepository(unitOfWork);
     Employee employee = new Employee();
     employee = repo.GetAll().Where(x => x.EmployeeId == model.EmployeeId).FirstOrDefault();
     AutoMapper.Mapper.Map(model, employee);
     repo.Update(employee);
     //unitOfWork.Commit();
     AutoMapper.Mapper.Map(employee, model);
     return model;
 }
示例#10
0
 public EmployeeModel SaveEmployee(EmployeeModel model)
 {
     //unitOfWork.StartTransaction();
     EmployeeRepository repo = new EmployeeRepository(unitOfWork);
     Employee employee = new Employee();
     AutoMapper.Mapper.Map(model, employee);
     repo.Insert(employee);
     //unitOfWork.Commit();
     AutoMapper.Mapper.Map(employee, model);
     return model;
 }
示例#11
0
        public IHttpActionResult GetComplaintByServiceProviderId(string serviceProviderId)
        {
            List<ComplaintBindingModel> complaintBindingModel = new List<ComplaintBindingModel>();
            List<ComplaintModel> complaintModel = new List<ComplaintModel>();
               // AutoMapper.Mapper.Map(jobBindingModel, jobModel);
            complaintModel = complaintService.GetComplaintListByServiceProviderId(serviceProviderId);
            AutoMapper.Mapper.Map(complaintModel, complaintBindingModel);
            EmployeeModel employeeModel = new EmployeeModel();
            ClientModel clientModel = new ClientModel();
            ServiceProviderModel ServiceProviderModel = new ServiceProviderModel();
            JobModel jobModel = new JobModel();
            complaintBindingModel.ForEach(x => {
                jobModel = jobService.GetJobById(x.JobId);
                employeeModel = employeeService.GetEmployeeById(x.EmployeeId);
                x.EmployeeName = employeeModel.FirstName;
                clientModel = clientService.GetClientById(x.ClientId);
                x.ClientName = clientModel.FirstName;
                ServiceProviderModel = serviceProviderService.GetServiceProviderById(x.ServiceProviderId);
                x.ServiceProviderName = ServiceProviderModel.CompanyName;
                x.JobAddress = jobModel.JobAddress;
                x.JobDescription = jobModel.Description;
                x.Description = x.Description;
                ApplicationUser user = UserManager.FindById(x.ClientId);
                if (user != null)
                {
                    x.ClientPhoneNumber = user.PhoneNumber;
                }

            });
            return Ok(complaintBindingModel);
        }
示例#12
0
        public IHttpActionResult MyTasks(string userId, string type)
        {
            List<JobBindingModel> jobBindingModel = new List<JobBindingModel>();
            try
            {
                //get job according to user id
                List<JobModel> jobModel = new List<JobModel>();
                JobStatus jobStatus = (JobStatus)Enum.Parse(typeof(JobStatus), type);
                jobModel = jobService.GetJobListByClientId(userId, jobStatus);
                AutoMapper.Mapper.Map(jobModel, jobBindingModel);
                //get job service mapping
                List<JobServiceMappingModel> jobServiceMappingModel = new List<JobServiceMappingModel>();
                string[] jobIds = jobBindingModel.Select(u => u.JobId.ToString()).ToArray();
                jobServiceMappingModel = jobServiceMappingService.GetJobServiceMappingByJobIds(jobIds);
                foreach (var item in jobServiceMappingModel)
                {
                    SubServiceModel subServiceModel = new SubServiceModel();
                    subServiceModel = subServicesService.GetSubServiceById(item.ServiceId);
                    item.ServiceName = subServiceModel.Description;
                }
                //get job service picture mapping
                List<JobServicePictureMappingModel> jobServicePictureMappingModel = new List<JobServicePictureMappingModel>();
                jobServicePictureMappingModel = jobServicePictruesMappingService.GetJobServicePictureMapping();
                jobBindingModel.ForEach(x =>
                {
                    x.JobServiceMappings = jobServiceMappingModel.Where(j => j.JobId == x.JobId).ToList();
                });
                jobServiceMappingModel.ForEach(x =>
                {
                    x.JobServicePictureMappings = jobServicePictureMappingModel.Where(j => j.JobServiceMappingId == x.JobServiceMappingId).ToList();
                });
                //get employee inforamtion
                jobBindingModel.ForEach(x =>
                {
                    //Get employee Name
                    EmployeeModel EmployeeModel = new EmployeeModel();
                    EmployeeModel = employeeService.GetEmployeeById(x.EmployeeId);
                    x.EmployeeModel = EmployeeModel;
                    UserLocationModel userLocationModel = new UserLocationModel();
                    userLocationModel = userLocationService.FindLocationById(x.ClientId);
                    if (x.JobAddress == null)
                    {
                        x.JobAddress = userLocationModel.Address;
                        x.Latitude = userLocationModel.Latitude;
                        x.Longitude = userLocationModel.Latitude;
                    }
                    if (x.StartDate != null && x.EndDate != null)
                    {
                        TimeSpan difference = Convert.ToDateTime(x.EndDate).AddDays(3) - Convert.ToDateTime(x.StartDate);
                        var days = difference.TotalDays;
                        if(days <= 3)
                        {
                            x.IsExpired = false;
                        }
                        else
                        {
                            x.IsExpired = true;
                        }
                    }

                });

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