Exemplo n.º 1
0
 public ClientModel SaveClient(ClientModel model)
 {
     //unitOfWork.StartTransaction();
     ClientRepository repo = new ClientRepository(unitOfWork);
     Client client = new Client();
     AutoMapper.Mapper.Map(model, client);
     repo.Insert(client);
     //unitOfWork.Commit();
     AutoMapper.Mapper.Map(client, model);
     return model;
 }
Exemplo n.º 2
0
 public ClientModel GetClientById(string clientId)
 {
     //unitOfWork.StartTransaction();
     ClientRepository repo = new ClientRepository(unitOfWork);
     ClientModel clientModel = new ClientModel();
     Client client = new Client();
     AutoMapper.Mapper.Map(clientModel, client);
      client = repo.GetAll().Where(x => x.ClientId == clientId).FirstOrDefault();
     //unitOfWork.Commit();
     AutoMapper.Mapper.Map(client, clientModel);
     return clientModel;
 }
Exemplo n.º 3
0
        public IHttpActionResult AcceptJob(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.EmployeeId = userId;
                jobModel.Status = JobStatus.Current;
                jobModel = jobService.UpadteJob(jobModel);
                AutoMapper.Mapper.Map(jobModel, jobBindingModel);
                //get job service mapping
                List<JobServiceMappingModel> jobServiceMappingModel = new List<JobServiceMappingModel>();
                jobServiceMappingModel = jobServiceMappingService.GetJobServiceMappingListByJobId(jobBindingModel.JobId);
                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.JobServiceMappings = jobServiceMappingModel.Where(j => j.JobId == jobBindingModel.JobId).ToList();

                jobServiceMappingModel.ForEach(x =>
                {
                    x.JobServicePictureMappings = jobServicePictureMappingModel.Where(j => j.JobServiceMappingId == x.JobServiceMappingId).ToList();
                });
                //get client inforamtion

                //Get Client Name
                ClientModel clientModel = new ClientModel();
                clientModel = clientService.GetClientById(jobBindingModel.ClientId);
                jobBindingModel.ClientModel = clientModel;
                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_ACCEPT_TYPE + "&data.message=" + Utility.Constants.MESSAGE_FOR_JOB_ACCEPT + "&data.time=" + System.DateTime.Now.ToString() + "&registration_id=" + user.DeviceToken + "";
                        var response = sendNotificationService.SendNotificationForAndroid(postData);
                    }
                    else if (user.DeviceType == Utility.Constants.DEVICE_TYPE_IOS)
                    {
                        string payload = "{\"aps\":{\"alert\":\"" + "Hi, " + Utility.Constants.MESSAGE_FOR_JOB_ACCEPT + "" + "\",\"badge\":1,\"sound\":\"default\"},\"JobId\":" + jobId + ",\"userId\":\"" + userId + "\",\"type\":\"" + Utility.Constants.JOB_ACCEPT_TYPE + "\"}";
                        sendNotificationService.SendNotificationForIOS(user.DeviceToken, payload);
                    }
                }





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

            return Json(jobBindingModel);
        }
Exemplo n.º 4
0
 public IHttpActionResult GetJobByJobId(Int32 jobId)
 {
     JobBindingModel jobBindingModel = new JobBindingModel();
     JobModel jobModel = new JobModel();
     AutoMapper.Mapper.Map(jobBindingModel, jobModel);
     jobModel = jobService.GetJobById(jobId);
     AutoMapper.Mapper.Map(jobModel, jobBindingModel);
     //Get Client Name
     ClientModel clientModel = new ClientModel();
     clientModel = clientService.GetClientById(jobBindingModel.ClientId);
     jobBindingModel.ClientName = clientModel.FirstName;
     //Get service City
     UserLocationModel userLocationModel = new UserLocationModel();
     userLocationModel = userLocationService.FindLocationById(jobBindingModel.ClientId);
     if (jobBindingModel.JobAddress == null || jobBindingModel.JobAddress == "")
     {
         jobBindingModel.JobAddress = userLocationModel.Address;
     }
     
     //Get serviceMapping
     JobServiceMappingModel jobServiceMappingModel = new JobServiceMappingModel();
     jobServiceMappingModel = jobServiceMappingService.GetJobServiceMappingByJobId(jobId);
     //get service name
     SubServiceModel subServiceModel = new SubServiceModel();
     subServiceModel = subServicesService.GetSubServiceById(jobServiceMappingModel.ServiceId);
     jobBindingModel.ServiceName = subServiceModel.Description;
     //get service picture mapping
     List<JobServicePictureMappingModel> jobServicePictureMappingModel = new List<JobServicePictureMappingModel>();
     jobServicePictureMappingModel = jobServicePictruesMappingService.GetJobServicePictureMappingByJobServiceMappingId(jobServiceMappingModel.JobServiceMappingId);
     jobServiceMappingModel.JobServicePictureMappings = jobServicePictureMappingModel;
     jobBindingModel.JobServiceMapping = jobServiceMappingModel;
     jobBindingModel.EmployeeModel = employeeServices.GetEmployeeById(jobBindingModel.EmployeeId);
     jobBindingModel.RatingModel = ratingService.GetRatingListByJobId(jobBindingModel.JobId);
     return Ok(jobBindingModel);
 }
Exemplo n.º 5
0
        public IHttpActionResult GetJobByServiceProviderId(string serviceProviderId)
        {
            //Get job
            List<JobBindingModel> jobBindingModel = new List<JobBindingModel>();
            List<JobModel> jobModel = new List<JobModel>();
            AutoMapper.Mapper.Map(jobBindingModel, jobModel);
            jobModel = jobService.GetJobListByServiceProviderId(serviceProviderId);
            AutoMapper.Mapper.Map(jobModel, jobBindingModel);

            jobBindingModel.ForEach(x =>
            {
                //Get Client Name
                ClientModel clientModel = new ClientModel();
                clientModel = clientService.GetClientById(x.ClientId);
                x.ClientName = clientModel.FirstName;
                //Get service City
                UserLocationModel userLocationModel = new UserLocationModel();
                userLocationModel = userLocationService.FindLocationById(x.ClientId);
                if (x.JobAddress == null || x.JobAddress=="")
                {
                    x.JobAddress = userLocationModel.Address;
                }
               
            });
            //Get serviceMapping
            List<JobServiceMappingModel> jobServiceMappingModel = new List<JobServiceMappingModel>();
            string[] jobIds = jobBindingModel.Select(u => u.JobId.ToString()).ToArray();
            jobServiceMappingModel = jobServiceMappingService.GetJobServiceMappingByJobIds(jobIds);
            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();
            });
            return Ok(jobBindingModel);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
 public ClientModel UpadteClient(ClientModel model)
 {
     //unitOfWork.StartTransaction();
     ClientRepository repo = new ClientRepository(unitOfWork);
     Client client = new Client();
     client = repo.GetAll().Where(x => x.ClientId == model.ClientId).FirstOrDefault();
     AutoMapper.Mapper.Map(model, client);
     repo.Update(client);
     //unitOfWork.Commit();
     AutoMapper.Mapper.Map(client, model);
     return model;
 }
Exemplo n.º 8
0
        public UserInfoViewModel GetUserInfo()
        {
            ExternalLoginData externalLogin = ExternalLoginData.FromIdentity(User.Identity as ClaimsIdentity);

            var id = User.Identity.GetUserId();
            var role = UserManager.GetRoles(id);
            // UserManager.FindByIdAsync(id);
            ClientModel clientDetail = new ClientModel();
            ServiceProviderModel serviceProviderModel = new ServiceProviderModel();
            if (role[0].ToString() == URFXRoles.Client.ToString())
            {
                clientDetail = clientService.GetClientById(id);
            }
            else
            {
                serviceProviderModel = serviceProviderService.GetServiceProviderById(id);
            }
            return new UserInfoViewModel
            {
                Email = UserManager.FindByName(User.Identity.GetUserName()).Email,
                HasRegistered = externalLogin == null,
                LoginProvider = externalLogin != null ? externalLogin.LoginProvider : null,
                UserName = User.Identity.GetUserName(),
                Client = clientDetail,
                ServiceProvider = serviceProviderModel


            };
        }
Exemplo n.º 9
0
        public IHttpActionResult GetClient(string id)
        {
            //Get Client Details
            RegisterClientBindingModel registerClientBindingModel = new RegisterClientBindingModel();
            ClientModel clientModel = new ClientModel();
            clientModel = clientService.GetClientById(id);
            AutoMapper.Mapper.Map(clientModel, registerClientBindingModel);
            var Email = UserManager.FindById(id) != null ? UserManager.FindById(id).Email : "";
            var PhoneNumber = UserManager.FindById(id) != null ? UserManager.FindById(id).PhoneNumber : "";
            registerClientBindingModel.Email = Email;
            registerClientBindingModel.PhoneNumber = PhoneNumber;
            //clientModel.FirstName = CommonFunctions.ReadResourceValue(clientModel.FirstName);
            //clientModel.LastName = CommonFunctions.ReadResourceValue(clientModel.LastName);
            //clientModel.NationalIdNumber = CommonFunctions.ReadResourceValue(clientModel.NationalIdNumber);


            //get rating for client
            List<ClientRatingBindingModel> clientRatingBindingModel = new List<ClientRatingBindingModel>();
            List<ClientRatingModel> clientRatingModel = new List<ClientRatingModel>();
            List<JobBindingModel> jobBindingModel = new List<JobBindingModel>();
            List<JobModel> jobModel = new List<JobModel>();
            AutoMapper.Mapper.Map(jobBindingModel, jobModel);
            jobModel = jobService.GetJobListByClientId(id);
            AutoMapper.Mapper.Map(jobModel, jobBindingModel);
            //Get employee Info for job

            ClientRatingModel ratingModel = new ClientRatingModel();

            string[] jobIds = jobBindingModel.Select(u => u.JobId.ToString()).ToArray();
            clientRatingModel = clientRatingService.GetClientRatingListByJobIds(jobIds);
            if (clientRatingModel.Count >0)
            {
                ratingModel.Behaivor = Convert.ToInt32(clientRatingModel.Select(c => c.Behaivor).Average());
                ratingModel.Communication = Convert.ToInt32(clientRatingModel.Select(c => c.Communication).Average());
                ratingModel.Corporation = Convert.ToInt32(clientRatingModel.Select(c => c.Corporation).Average());
                ratingModel.FriendLiness = Convert.ToInt32(clientRatingModel.Select(c => c.FriendLiness).Average());
                ratingModel.OverallSatisfaction = Convert.ToInt32(clientRatingModel.Select(c => c.OverallSatisfaction).Average());
                ratingModel.UnderStanding = Convert.ToInt32(clientRatingModel.Select(c => c.UnderStanding).Average());
            }
            ratingModel.TotalRating = CommonFunctions.GetTotalFeedbackForClient(ratingModel);

            //Get Location of client
            UserLocationModel model = locationService.FindLocationById(id);
            //
            registerClientBindingModel.ClientRatingModelList = clientRatingModel;
            registerClientBindingModel.AverageRating = ratingModel.TotalRating;
            registerClientBindingModel.UserLocationModel = model;




            return Ok(registerClientBindingModel);
        }
Exemplo n.º 10
0
 public IHttpActionResult UpdateQuickBlox(string userId, string quickBloxId)
 {
     try {
         ClientModel clientModel = new ClientModel();
         clientModel = clientService.GetClientById(userId);
         clientModel.QuickBloxId = quickBloxId;
         clientModel.Registred = true;
         clientModel = clientService.UpadteClient(clientModel);
         return Json(clientModel);
     }
     catch(Exception ex)
     {
         return BadRequest(ex.Message);
     }
 }
Exemplo n.º 11
0
 public async Task<IHttpActionResult> ResendOTP(string clientId)
 {
     //get user
     var user = await UserManager.FindByIdAsync(clientId);
     //Get client Details
     ClientModel clientModel = new ClientModel();
     clientModel = clientService.GetClientById(clientId);
     //generate OTP 
     Random r = new Random();
     int randNum = r.Next(1000000);
     string sixDigitNumber = randNum.ToString("D6");
     clientModel.OTP = sixDigitNumber;
     //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 > 0 ? ":" + HttpContext.Current.Request.Url.Port : "";
     var exactPath = scheme + "://" + host + port + "/Content/URFXTheme/images/logo.png";
     //var exactPath = scheme + "://" + host + "/Content/URFXTheme/images/logo.png";
     string text = System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath(Utility.Constants.CONFIRMATION_OTP_PATH));
     String Body = "";
     Body = String.Format(text, user.UserName, sixDigitNumber, exactPath);
     try
     {
         await UserManager.SendEmailAsync(user.Id, Subject, Body);
     }
     catch (Exception ex)
     {
         Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
         return BadRequest(ex.Message);
     }
     //update Client
     clientModel = clientService.UpadteClient(clientModel);
     return Ok(clientModel);
 }
Exemplo n.º 12
0
        public async Task<IHttpActionResult> ConfirmOTP(string email, string OTP)
        {
            try
            {
                if (email == null || OTP == null)
                {
                    return BadRequest("email and OTP is not provided");
                }
                var user = new ApplicationUser();
                user = await UserManager.FindByEmailAsync(email);
                ClientModel clientModel = new ClientModel();
                clientModel = clientService.GetClientById(user.Id);
                if (clientModel.OTP != OTP)
                {
                    return BadRequest("OTP you entered is not correct");
                }
                else
                {
                    user.EmailConfirmed = true;
                    IdentityResult result = await UserManager.UpdateAsync(user);
                }
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                return BadRequest(ex.Message);
            }
            return Ok();

        }
Exemplo n.º 13
0
        public IHttpActionResult DeleteClient(string id)
        {
            ClientModel clientModel = new ClientModel();
            clientModel = clientService.GetClientById(id);
            if (clientModel == null)
            {
                return NotFound();
            }
            clientService.DeleteClient(id);
            ApplicationUser user = UserManager.FindById(id);

            IdentityResult result = UserManager.Delete(user);
            if (!result.Succeeded)
            {
                return GetErrorResult(result);
            }
             return Ok();
        }
Exemplo n.º 14
0
        public async Task<IHttpActionResult> PutClient()
        {
            RegisterClientBindingModel clientBindingModel = new RegisterClientBindingModel();
            ClientModel clientModel = new ClientModel();
            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 result = resultModel.FormData["model"];
                //var model = result.Substring(1, result.Length - 2);
                clientBindingModel = JsonConvert.DeserializeObject<RegisterClientBindingModel>(result);
                AutoMapper.Mapper.Map(clientBindingModel, clientModel);
                ClientModel clientCheckModel = new ClientModel();
                clientCheckModel = clientService.GetClientById(clientModel.ClientId);
                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;
                            file.SaveAs(Path.Combine(root, Utility.Constants.CLIENT_PROFILE_IMAGE_PATH, fileName));
                            clientModel.ProfilePicturePath = fileName;

                        }

                    }
             }
                if (clientModel.ProfilePicturePath == null)
                {
                    clientModel.ProfilePicturePath = clientCheckModel.ProfilePicturePath;
                }

                clientService.UpadteClient(clientModel);
                AutoMapper.Mapper.Map(clientModel, clientBindingModel);
            }
            catch(Exception ex)
            {
                return BadRequest(ex.Message);
            }




            return Ok(clientBindingModel);
        }
Exemplo n.º 15
0
 // GET: api/Jobs
 public List<JobBindingModel> GetJob()
 {
     List<JobBindingModel> jobBindingModel = new List<JobBindingModel>();
     List<JobModel> jobModel = new List<JobModel>();
     AutoMapper.Mapper.Map(jobBindingModel, jobModel);
     jobModel = jobService.GetAllJobs();
     AutoMapper.Mapper.Map(jobModel, jobBindingModel);
     jobBindingModel.ForEach(x =>
     {
         //Get Client Name
         ClientModel clientModel = new ClientModel();
         clientModel = clientService.GetClientById(x.ClientId);
         x.ClientName = clientModel.FirstName;
         //Get service City
         UserLocationModel userLocationModel = new UserLocationModel();
         userLocationModel = userLocationService.FindLocationById(x.ClientId);
         if (x.JobAddress == null || x.JobAddress == "")
         {
             x.JobAddress = userLocationModel.Address;
         }
         //Get Employee Name 
         if (x.EmployeeId != null)
         {
             x.EmployeeModel = employeeServices.GetEmployeeById(x.EmployeeId);
         }
     });
     //Get serviceMapping
     List<JobServiceMappingModel> jobServiceMappingModel = new List<JobServiceMappingModel>();
     string[] jobIds = jobBindingModel.Select(u => u.JobId.ToString()).ToArray();
     jobServiceMappingModel = jobServiceMappingService.GetJobServiceMappingByJobIds(jobIds);
     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();
     });
     return jobBindingModel;
 }
Exemplo n.º 16
0
        public IHttpActionResult MyJobs(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.GetJobsByEmployeeId(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 client inforamtion
                jobBindingModel.ForEach(x =>
                {
                    //Get Client Name
                    ClientModel clientModel = new ClientModel();
                    clientModel = clientService.GetClientById(x.ClientId);
                    ApplicationUser user = UserManager.FindById(clientModel.ClientId);
                    if (user != null)
                    {
                        clientModel.PhoneNumber = user.PhoneNumber;
                    }
                    x.ClientModel = clientModel;
                    userLocationModel = userLocationService.FindLocationById(x.ClientId);
                    if (x.JobAddress == null || x.JobAddress == "")
                    {
                        x.JobAddress = userLocationModel.Address;
                        x.Latitude = userLocationModel.Latitude;
                        x.Longitude = userLocationModel.Latitude;
                    }


                });

            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                return BadRequest(ex.Message);
            }
            return Ok(jobBindingModel);
        }
Exemplo n.º 17
0
        public async Task<IHttpActionResult> RegisterClient(RegisterClientBindingModel model)
        {
            //using (var dataContext = new URFXDbContext())
            //{
            //    TransactionScope transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled);
            //    {
            try
            {
                if (model.RegistrationType == RegistrationType.Simple)
                {
                    var user = new ApplicationUser()
                    {
                        UserName = model.Email,
                        Email = model.Email,
                        PhoneNumber = model.PhoneNumber,
                        DeviceType = model.DeviceType,
                        DeviceToken = model.DeviceToken,
                        RegistrationType = model.RegistrationType,
                        FacebookId = model.FacebookId,
                        GoogleId = model.GoogleId,
                        TwitterId = model.TwitterId
                    };
                    IdentityResult result = await UserManager.CreateAsync(user, model.Password);
                    if (!result.Succeeded)
                    {
                        // transaction.Dispose();
                        return GetErrorResult(result);
                    }

                    else
                    {
                        model.ClientId = user.Id;
                        IdentityResult resultRoleCreated = await UserManager.AddToRoleAsync(user.Id, URFXRoles.Client.ToString());
                        if (!resultRoleCreated.Succeeded)
                        {
                            // transaction.Dispose();
                            return GetErrorResult(resultRoleCreated);
                        }
                        else
                        {
                           try
                            {
                                //generate OTP 
                                Random r = new Random();
                                int randNum = r.Next(1000000);
                                string sixDigitNumber = randNum.ToString("D6");
                                model.OTP = sixDigitNumber;
                                //Save Client
                                ClientModel clientModel = new ClientModel();
                                AutoMapper.Mapper.Map(model, clientModel);
                                clientModel = clientService.SaveClient(clientModel);
                                AutoMapper.Mapper.Map(clientModel, model);
                                //save location for client
                                UserLocationModel locationModel = new UserLocationModel();
                                locationModel.UserId = user.Id;
                                locationModel.CityId = model.CityId;
                                locationModel.DistrictId = 1;
                                locationModel.Latitude = model.Latitude;
                                locationModel.Longitude = model.Longitude;
                                locationModel.Address = model.Address;
                                if (locationModel.Address != null)
                                {
                                    locationModel = userLocationService.InsertUserLocation(locationModel);
                                }

                                //Send Email
                                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 > 0 ? ":" + 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

                                }
                                // var exactPath = scheme + "://" + host + port + "/Content/URFXTheme/images/logo.png";
                                //var exactPath = scheme + "://" + host + "/Content/URFXTheme/images/logo.png";
                                var Subject = Utility.Constants.CONFIRMATION_SUBJECT;
                                string text = System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath(Utility.Constants.CONFIRMATION_OTP_PATH));
                                String Body = "";
                                Body = String.Format(text, user.UserName, sixDigitNumber, exactPath);
                                try
                                {
                                    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);
                            }
                        }
                    }
                }
                else
                {
                    if (model.Password == null && model.RegistrationType == RegistrationType.Facebook)
                    {
                        model.Password = model.FacebookId;
                    }
                    else if (model.Password == null && model.RegistrationType == RegistrationType.Google)
                    {
                        model.Password = model.GoogleId;
                    }
                    else if (model.Password == null && model.RegistrationType == RegistrationType.Twitter)
                    {
                        model.Password = model.TwitterId;
                    }
                    var checkUser = UserManager.FindByEmail(model.Email);
                    if (checkUser == null)
                    {
                        var user = new ApplicationUser()
                        {
                            UserName = model.Email,
                            Email = model.Email,
                            PhoneNumber = model.PhoneNumber,
                            DeviceType = model.DeviceType,
                            DeviceToken = model.DeviceToken,
                            RegistrationType = model.RegistrationType,
                            FacebookId = model.FacebookId,
                            GoogleId = model.GoogleId,
                            TwitterId = model.TwitterId,
                            IsRegister = true,
                            IsLogin = false

                        };
                        IdentityResult result = await UserManager.CreateAsync(user, model.Password);
                        if (!result.Succeeded)
                        {
                            //  transaction.Dispose();
                            return GetErrorResult(result);
                        }

                        else
                        {
                            model.ClientId = user.Id;
                            IdentityResult resultRoleCreated = await UserManager.AddToRoleAsync(user.Id, URFXRoles.Client.ToString());
                            //Save Client
                            try
                            {
                                ClientModel clientModel = new ClientModel();
                                AutoMapper.Mapper.Map(model, clientModel);
                                clientModel = clientService.SaveClient(clientModel);
                                AutoMapper.Mapper.Map(clientModel, model);

                                //save location for client
                                UserLocationModel locationModel = new UserLocationModel();
                                locationModel.UserId = user.Id;
                                locationModel.CityId = model.CityId;
                                locationModel.DistrictId = 1;
                                locationModel.Latitude = model.Latitude;
                                locationModel.Longitude = model.Longitude;
                                locationModel.Address = model.Address;
                                if (locationModel.Address != null)
                                {
                                    locationModel = userLocationService.InsertUserLocation(locationModel);
                                }
                                //check if register using facebook,google,twitter
                                string token = GetToken(user.UserName, model.Password);
                                var json = JsonConvert.DeserializeObject(token);
                                //    transaction.Complete();
                                return Json(json);

                            }
                            catch (Exception ex)
                            {
                                //  transaction.Dispose();
                                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                                return BadRequest(ex.Message);
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            if (checkUser.RegistrationType == model.RegistrationType)
                            {

                                checkUser.DeviceType = model.DeviceType;
                                checkUser.DeviceToken = model.DeviceToken;
                                checkUser.IsLogin = true;
                                //UserManager.Update(checkUser);
                                IdentityResult result = await UserManager.UpdateAsync(checkUser);
                                //update client
                                ClientModel clientModel = new ClientModel();
                                clientModel = clientService.GetClientById(checkUser.Id);
                                //if (clientModel.ClientId != null)
                                //{
                                //    clientModel.QuickBloxId = model.QuickBloxId;
                                //    clientModel = clientService.UpadteClient(clientModel);
                                //}

                                //update location for client
                                UserLocationModel locationModel = new UserLocationModel();
                                locationModel = userLocationService.FindLocationById(checkUser.Id);
                                locationModel.UserId = checkUser.Id;
                                locationModel.CityId = model.CityId;
                                locationModel.DistrictId = 1;
                                locationModel.Latitude = model.Latitude;
                                locationModel.Longitude = model.Longitude;
                                locationModel.Address = model.Address;
                                if (locationModel.UserLocationId > 0)
                                {
                                    locationModel = userLocationService.UpadteUserLocation(locationModel);
                                }
                                else
                                {
                                    locationModel = userLocationService.InsertUserLocation(locationModel);
                                }
                                var resetToken = await UserManager.GeneratePasswordResetTokenAsync(checkUser.Id);
                                await UserManager.ResetPasswordAsync(checkUser.Id, resetToken, model.Password);
                                string token = GetToken(checkUser.UserName, model.Password);
                                var json = JsonConvert.DeserializeObject(token);
                                //   transaction.Complete();
                                return Json(json);
                            }

                            else
                            {
                                if (model.RegistrationType == RegistrationType.Google)
                                {
                                    checkUser.RegistrationType = model.RegistrationType;
                                    checkUser.GoogleId = model.GoogleId;
                                    checkUser.DeviceType = model.DeviceType;
                                    checkUser.DeviceToken = model.DeviceToken;
                                    checkUser.IsLogin = true;
                                    //UserManager.Update(checkUser);
                                    IdentityResult result = await UserManager.UpdateAsync(checkUser);
                                    //update client
                                    ClientModel clientModel = new ClientModel();
                                    clientModel = clientService.GetClientById(checkUser.Id);
                                    //if (clientModel.ClientId != null)
                                    //{
                                    //    clientModel.QuickBloxId = model.QuickBloxId;
                                    //    clientModel = clientService.UpadteClient(clientModel);
                                    //}
                                    
                                    //update location for client
                                    UserLocationModel locationModel = new UserLocationModel();
                                    locationModel = userLocationService.FindLocationById(checkUser.Id);
                                    locationModel.UserId = checkUser.Id;
                                    locationModel.CityId = model.CityId;
                                    locationModel.DistrictId = 1;
                                    locationModel.Latitude = model.Latitude;
                                    locationModel.Longitude = model.Longitude;
                                    locationModel.Address = model.Address;
                                    if (locationModel.UserLocationId > 0)
                                    {
                                        locationModel = userLocationService.UpadteUserLocation(locationModel);
                                    }
                                    else
                                    {
                                        locationModel = userLocationService.InsertUserLocation(locationModel);
                                    }
                                    var resetToken = await UserManager.GeneratePasswordResetTokenAsync(checkUser.Id);
                                    await UserManager.ResetPasswordAsync(checkUser.Id, resetToken, model.Password);
                                    string token = GetToken(checkUser.UserName, model.Password);
                                    var json = JsonConvert.DeserializeObject(token);
                                    //   transaction.Complete();
                                    return Json(json);
                                }
                                else
                                {
                                    checkUser.RegistrationType = model.RegistrationType;
                                    checkUser.TwitterId = model.TwitterId;
                                    checkUser.DeviceType = model.DeviceType;
                                    checkUser.DeviceToken = model.DeviceToken;
                                    checkUser.IsLogin = true;
                                    //UserManager.Update(checkUser);
                                    IdentityResult result = await UserManager.UpdateAsync(checkUser);
                                    //update client
                                    ClientModel clientModel = new ClientModel();
                                    clientModel = clientService.GetClientById(checkUser.Id);
                                    //if (clientModel.ClientId != null)
                                    //{
                                    //    clientModel.QuickBloxId = model.QuickBloxId;
                                    //    clientModel = clientService.UpadteClient(clientModel);
                                    //}
                                    
                                    //update location for client
                                    UserLocationModel locationModel = new UserLocationModel();
                                    locationModel = userLocationService.FindLocationById(checkUser.Id);
                                    locationModel.UserId = checkUser.Id;
                                    locationModel.CityId = model.CityId;
                                    locationModel.DistrictId = 1;
                                    locationModel.Latitude = model.Latitude;
                                    locationModel.Longitude = model.Longitude;
                                    locationModel.Address = model.Address;
                                    if (locationModel.UserLocationId > 0)
                                    {
                                        locationModel = userLocationService.UpadteUserLocation(locationModel);
                                    }
                                    else
                                    {
                                        locationModel = userLocationService.InsertUserLocation(locationModel);
                                    }
                                    var resetToken = await UserManager.GeneratePasswordResetTokenAsync(checkUser.Id);
                                    await UserManager.ResetPasswordAsync(checkUser.Id, resetToken, model.Password);
                                    string token = GetToken(checkUser.UserName, model.Password);
                                    var json = JsonConvert.DeserializeObject(token);
                                    //   transaction.Complete();
                                    return Json(json);
                                }
                            }


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


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