public override int GetHashCode()
        {
            int hash = 1;

            if (Date.Length != 0)
            {
                hash ^= Date.GetHashCode();
            }
            if (CityOfBirth.Length != 0)
            {
                hash ^= CityOfBirth.GetHashCode();
            }
            if (CountryOfBirth.Length != 0)
            {
                hash ^= CountryOfBirth.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Example #2
0
        public async Task <IHttpActionResult> Register(UserRegistrationModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    var modelErrors = new List <string>();
                    foreach (var modelState in ModelState.Values)
                    {
                        foreach (var modelError in modelState.Errors)
                        {
                            modelErrors.Add(modelError.ErrorMessage);
                        }
                    }
                    return(Content(HttpStatusCode.BadRequest, modelErrors[0].ToString()));
                }

                if (await _bucket.ExistsAsync(model.Email))
                {
                    return(Content(HttpStatusCode.Conflict, new Error($"Email '{model.Email}' already exists")));
                }
                if (await _bucket.ExistsAsync(model.EmiratId))
                {
                    return(Content(HttpStatusCode.Conflict, new Error($"EmiratId '{model.EmiratId}' already exists")));
                }
                if (await _bucket.ExistsAsync(model.Phone))
                {
                    return(Content(HttpStatusCode.Conflict, new Error($"Phone '{model.EmiratId}' already exists")));
                }
                Body body = new Body();
                body.UniFiedNumber  = model.Body.UniFiedNumber;
                body.PlaceOfBirthAr = model.Body.PlaceOfBirthAr;
                body.PlaceOfBirthEn = model.Body.PlaceOfBirthEn;
                body.DateOfBirth    = model.Body.DateOfBirth;

                if (model.Body.IdentityCard != null)
                {
                    IdentityCard identityCard = new IdentityCard();
                    identityCard.Number     = model.Body.IdentityCard.Number;
                    identityCard.IssueDate  = DateTime.Today;
                    identityCard.ExpiryDate = DateTime.Today;
                    body.IdentityCard       = identityCard;
                }

                if (model.Body.Nationality != null)
                {
                    Nationality nationality = new Nationality();
                    nationality.ArDesc = model.Body.Nationality.ArDesc;
                    nationality.EnDesc = model.Body.Nationality.EnDesc;
                    body.Nationality   = nationality;
                }

                if (model.Body.PersonName != null)
                {
                    PersonName personName = new PersonName();
                    personName.FullArabicName    = model.Body.PersonName.FirstNameArabic;
                    personName.FirstNameArabic   = model.Body.PersonName.FirstNameArabic;
                    personName.SecondNameArabic  = model.Body.PersonName.SecondNameArabic;
                    personName.ThirdNameArabic   = model.Body.PersonName.ThirdNameArabic;
                    personName.FourthNameArabic  = model.Body.PersonName.FourthNameArabic;
                    personName.FamilyNameArabic  = model.Body.PersonName.FamilyNameArabic;
                    personName.FullEnglishName   = model.Body.PersonName.FullEnglishName;
                    personName.FirstNameEnglish  = model.Body.PersonName.FirstNameEnglish;
                    personName.SecondNameEnglish = model.Body.PersonName.SecondNameEnglish;
                    personName.ThirdNameEnglish  = model.Body.PersonName.ThirdNameEnglish;
                    personName.FourthNameEnglish = model.Body.PersonName.FourthNameEnglish;
                    personName.FamilyNameEnglish = model.Body.PersonName.FamilyNameEnglish;
                    Tribe tribe = new Tribe();
                    tribe.ArDesc     = model.Body.PersonName.Tribe.ArDesc;
                    tribe.EnDesc     = model.Body.PersonName.Tribe.EnDesc;
                    personName.Tribe = tribe;
                    body.PersonName  = personName;
                }
                if (model.Body.Gender != null)
                {
                    Gender gender = new Gender();
                    gender.ArDesc = model.Body.Gender.ArDesc;
                    gender.EnDesc = model.Body.Gender.EnDesc;
                    body.Gender   = gender;
                }

                if (model.Body.CountryOfBirth != null)
                {
                    CountryOfBirth countryOfBirth = new CountryOfBirth();
                    countryOfBirth.ArDesc = model.Body.CountryOfBirth.ArDesc;
                    countryOfBirth.EnDesc = model.Body.CountryOfBirth.EnDesc;
                    body.CountryOfBirth   = countryOfBirth;
                }

                if (model.Body.EmirateOfBirth != null)
                {
                    EmirateOfBirth emirateOfBirth = new EmirateOfBirth();
                    emirateOfBirth.ArDesc = model.Body.EmirateOfBirth.ArDesc;
                    emirateOfBirth.EnDesc = model.Body.EmirateOfBirth.EnDesc;
                    body.EmirateOfBirth   = emirateOfBirth;
                }

                if (model.Body.EmirateOfBirth != null)
                {
                    CityOfBirth cityOfBirth = new CityOfBirth();
                    cityOfBirth.ArDesc = model.Body.CityOfBirth.ArDesc;
                    cityOfBirth.EnDesc = model.Body.CityOfBirth.EnDesc;
                    body.CityOfBirth   = cityOfBirth;
                }

                if (model.Body.MaritalStatus != null)
                {
                    MaritalStatus maritalStatus = new MaritalStatus();
                    maritalStatus.EnDesc = model.Body.MaritalStatus.EnDesc;
                    maritalStatus.ArDesc = model.Body.MaritalStatus.ArDesc;
                    body.MaritalStatus   = maritalStatus;
                }

                if (model.Body.Address != null)
                {
                    Address address = new Address();
                    address.AddressLine1 = model.Body.Address.AddressLine1;
                    address.AddressLine1 = model.Body.Address.AddressLine1;
                    address.City         = model.Body.Address.City;
                    address.State        = model.Body.Address.State;
                    address.Country      = model.Body.Address.Country;
                    body.Address         = address;
                }

                if (model.Body.Religion != null)
                {
                    Religion religion = new Religion();
                    religion.ArDesc = model.Body.Religion.ArDesc;
                    religion.EnDesc = model.Body.Religion.EnDesc;
                    body.Religion   = religion;
                }
                TrnHeader trnHeader = new TrnHeader();
                if (model.Body.Religion != null)
                {
                    trnHeader.ServiceProviderEntity = "APTC";
                }

                var eotp = GenerateOtp();
                var motp = GenerateOtp();
                sendEmail.SendOtpViaEmail(model.Email, model.Body.PersonName.FirstNameEnglish, eotp);
                //SendOtpViaMobile(model.Phone, motp);
                string password = Guid.NewGuid().ToString("d").Substring(1, 4);
                var    userDoc  = new Document <UserRegistrationModel>()
                {
                    Id      = "Customer_" + model.EmiratId,
                    Content = new UserRegistrationModel
                    {
                        IsVerifiedOtp = false,
                        EmailOtp      = eotp,
                        MobileOtp     = motp,
                        Language      = model.Language,
                        Email         = model.Email,
                        Password      = password,
                        Phone         = model.Phone,
                        OtherPhone    = model.OtherPhone,
                        EmiratId      = model.EmiratId,
                        PassPort      = model.PassPort,
                        Body          = body,
                        TrnHeader     = trnHeader
                    },
                };

                var result = await _bucket.InsertAsync(userDoc);

                if (!result.Success)
                {
                    return(Content(HttpStatusCode.InternalServerError, new Error(result.Message)));
                }
                else
                {
                    //sendEmail.SendUserIdAndPassword(model.Email, password);
                    var userDocLogin = new Document <Login>()
                    {
                        Id      = "Login_" + model.Email,
                        Content = new Login
                        {
                            Created_by   = model.Email,
                            Created_on   = DateTime.Now.ToString(),
                            UserId       = model.Email,
                            Password     = password,
                            Pre_language = model.Language,
                            Status       = "A",
                            Type         = "CAST",
                            Role         = "User",
                        },
                    };
                    IBucket _bucketLogin = ClusterHelper.GetBucket(ConfigurationManager.AppSettings.Get("CouchbaseLoginBucket"));
                    var     resultLogin  = await _bucketLogin.InsertAsync(userDocLogin);

                    return(Content(HttpStatusCode.Accepted, result.Document.Id));
                }
            }
            catch (Exception ex)
            {
                return(Content(HttpStatusCode.Forbidden, ex.StackTrace));
            }
        }