Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }