コード例 #1
0
        public ActionResult Details(CitizenProfileViewModel profile)
        {
            int languageId = CultureHelper.GetCurrentLanguageId(Request.Cookies["_culture"]);

            try
            {
                if (profile.LanguageId == 0)
                {
                    profile.LanguageId = CultureHelper.GetDefaultLanguageId();
                }

                var userProfile = _db.UserProfiles.Find(profile.Id);

                if (userProfile != null)
                {
                    userProfile.GenderLookupId     = profile.GenderLookupId;
                    userProfile.PreferedLanguageId = profile.PrefferdLanguage;
                    userProfile.Birthday           = profile.BirthDay;
                    userProfile.Fax                   = profile.Fax;
                    userProfile.IdNumber              = profile.IdNumber;
                    userProfile.PhoneNumber           = profile.PhoneNumber;
                    userProfile.RegionId              = profile.RegionId;
                    userProfile.CityId                = profile.CityId;
                    userProfile.ProvinceId            = profile.ProvinceId;
                    userProfile.MartialStatusLookupId = profile.MartialStatusLookupId;
                    userProfile.ProfilePhoto          = profile.ProfilePath;
                    userProfile.Mobile                = profile.Mobile;

                    _db.Entry(userProfile).State = EntityState.Modified;
                    _db.SaveChanges();

                    var userProfileTrans = _db.UserProfileTranslations.FirstOrDefault(r =>
                                                                                      r.UserProfileId == userProfile.Id && r.LanguageId == profile.LanguageId);
                    if (userProfileTrans != null)
                    {
                        userProfileTrans.FullName         = profile.FullName;
                        userProfileTrans.Address          = profile.Address;
                        _db.Entry(userProfileTrans).State = EntityState.Modified;
                    }
                    else
                    {
                        userProfileTrans = new UserProfileTranslation()
                        {
                            UserProfileId = userProfile.Id,
                            IsDefault     = false,
                            LanguageId    = profile.LanguageId,
                            FullName      = profile.FullName,
                            Address       = profile.Address,
                        };
                        _db.UserProfileTranslations.Add(userProfileTrans);
                    }
                }

                _db.SaveChanges();
                return(RedirectToAction("Details", new { id = profile.Id }));
            }
            catch (Exception ex)
            {
                LogHelper.LogException(User.Identity.Name, ex, "Error While Updating profile");
            }
            var prefferdLanguage = LookupHelper.GetLookupDetailsByMasterId((int)GeneralEnums.MasterLookupEnums.PrefferdLanguage,
                                                                           Request.Cookies["_culture"]);

            ViewBag.PrefferdLanguage = new SelectList(prefferdLanguage, "Id", "Name", profile.PrefferdLanguage);
            ViewBag.GenderLookupId   =
                new SelectList(
                    LookupHelper.GetLookupDetailsByMasterId((int)GeneralEnums.MasterLookupEnums.Gender,
                                                            Request.Cookies["_culture"]), "Id", "Name");
            ViewBag.MartialStatusLookupId = new SelectList(LookupHelper.GetLookupDetailsByMasterId((int)GeneralEnums.MasterLookupEnums.MartialStatus, Request.Cookies["_culture"]), "Id", "Name", profile.MartialStatusLookupId);
            ViewBag.ProvinceId            = new SelectList(LookupHelper.GetLookupDetailsByMasterId((int)GeneralEnums.MasterLookupEnums.Province, Request.Cookies["_culture"]), "Id", "Name", profile.ProvinceId);
            ViewBag.RegionId = new SelectList(LookupHelper.GetLookupDetailsByMasterId((int)GeneralEnums.MasterLookupEnums.Region, Request.Cookies["_culture"]), "Id", "Name", profile.RegionId);
            ViewBag.CityId   = new SelectList(LookupHelper.GetLookupDetailsByMasterId((int)GeneralEnums.MasterLookupEnums.City, Request.Cookies["_culture"]), "Id", "Name", profile.CityId);

            return(View(profile));
        }
コード例 #2
0
        public JsonResult EditProfile(ProfileViewModel profile)
        {
            try
            {
                var prof = _db.UserProfiles.Find(profile.Id);
                if (prof != null && prof.Status != (int)GeneralEnums.StatusEnum.Deleted)
                {
                    prof.Birthday              = profile.BirthDay;
                    prof.Fax                   = profile.Fax ?? string.Empty;
                    prof.GenderLookupId        = profile.GenderLookupId;
                    prof.ProvinceId            = profile.ProvinceId;
                    prof.CityId                = profile.CityId;
                    prof.RegionId              = profile.RegionId;
                    prof.Email                 = profile.Email;
                    prof.MartialStatusLookupId = profile.MartialStatusLookupId;
                    prof.DepartmentId          = profile.Department;
                    prof.ManagerId             = profile.ManagerId;
                    prof.PreferedLanguageId    = profile.PrefferdLanguage;
                    prof.PhoneNumber           = profile.PhoneNumber ?? string.Empty;
                    prof.Mobile                = profile.Mobile ?? string.Empty;
                    prof.IdNumber              = profile.IdNumber ?? string.Empty;
                    prof.Status                = profile.Status;
                    prof.StatusEditDescription = profile.Status != (int)GeneralEnums.StatusEnum.Active ? profile.StatusEditDescription : string.Empty;
                    _db.Entry(prof).State      = EntityState.Modified;
                    _db.SaveChanges();

                    int languageId = CultureHelper.GetCurrentLanguageId(Request.Cookies["_culture"]);

                    var profTrans = _db.UserProfileTranslations.FirstOrDefault(r => r.UserProfileId == prof.Id && r.LanguageId == profile.LanguageId);
                    if (profTrans != null)
                    {
                        profTrans.Address          = profile.Address ?? string.Empty;
                        profTrans.FullName         = profile.FullName;
                        _db.Entry(profTrans).State = EntityState.Modified;
                    }
                    else
                    {
                        profTrans = new UserProfileTranslation()
                        {
                            UserProfileId = prof.Id,
                            Address       = profile.Address,
                            IsDefault     = false,
                            LanguageId    = profile.LanguageId,
                            FullName      = profile.FullName
                        };
                        _db.UserProfileTranslations.Add(profTrans);
                    }

                    _db.SaveChanges();

                    var userOffDays = _db.UserProfileOffDays.Where(r => r.UserProfileId == prof.Id);
                    foreach (var day in userOffDays)
                    {
                        _db.UserProfileOffDays.Remove(day);
                    }

                    _db.SaveChanges();
                    foreach (var dayId in profile.WeekDaysOff)
                    {
                        _db.UserProfileOffDays.Add(new UserProfileOffDay()
                        {
                            UserProfileId = prof.Id,
                            CreatedOn     = DateTime.Now,
                            CreatedBy     = User.Identity.Name,
                            Status        = (int)GeneralEnums.StatusEnum.Active,
                            WeekDay       = dayId.ToString()
                        });
                    }
                    _db.SaveChanges();
                }

                return(Json(profile, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                LogHelper.LogException(User.Identity.Name, ex, "Error While editing profile (Post)");
                return(null);
            }
        }
コード例 #3
0
        public JsonResult AddProfile(ProfileViewModel profile)
        {
            var companyId = SessionHelper.GetCompanyId();
            var account   = _db.UserProfiles.FirstOrDefault(r => r.Username != profile.Email && r.Status == (int)GeneralEnums.StatusEnum.Deleted && profile.CompanyId == companyId);

            if (account != null && account.Status == (int)GeneralEnums.StatusEnum.Deactive)
            {
                string Msg = "تم تعطيل هذا الحساب من قبل المسؤول ";

                return(Json(new { Id = 0, Msg = Msg }, JsonRequestBehavior.AllowGet));
            }

            var user = new ApplicationUser {
                UserName = profile.Email, Email = profile.Email
            };
            var result     = UserManager.CreateAsync(user, profile.Password);
            int languageId = CultureHelper.GetCurrentLanguageId(Request.Cookies["_culture"]);

            if (result.Result.Succeeded)
            {
                string customerId = null;

                try
                {
                    var profil = new UserProfile()
                    {
                        Fax                   = profile.Fax,
                        Birthday              = profile.BirthDay,
                        CreatedOn             = DateTime.Now,
                        GenderLookupId        = profile.GenderLookupId,
                        ProvinceId            = profile.ProvinceId,
                        CityId                = profile.CityId,
                        RegionId              = profile.RegionId,
                        IdNumber              = profile.IdNumber ?? string.Empty,
                        PhoneNumber           = profile.PhoneNumber ?? string.Empty,
                        Mobile                = profile.Mobile ?? string.Empty,
                        MartialStatusLookupId = profile.MartialStatusLookupId,
                        ManagerId             = profile.ManagerId,
                        DepartmentId          = profile.Department,
                        PreferedLanguageId    = profile.PrefferdLanguage,
                        Status                = (int)GeneralEnums.StatusEnum.Active,
                        Username              = profile.Username,
                        Email                 = profile.Email,
                        CompanyId             = SessionHelper.GetCompanyId(),
                    };
                    _db.UserProfiles.Add(profil);
                    _db.SaveChanges();

                    var profTrans = new UserProfileTranslation()
                    {
                        Address       = profile.Address,
                        FullName      = profile.FullName,
                        IsDefault     = languageId == CultureHelper.GetDefaultLanguageId(),
                        LanguageId    = languageId,
                        UserProfileId = profil.Id
                    };
                    _db.UserProfileTranslations.Add(profTrans);
                    if (!profTrans.IsDefault)
                    {
                        var profTrans1 = new UserProfileTranslation()
                        {
                            Address       = profile.Address ?? string.Empty,
                            FullName      = profile.FullName,
                            IsDefault     = true,
                            LanguageId    = CultureHelper.GetDefaultLanguageId(),
                            UserProfileId = profil.Id
                        };
                        _db.UserProfileTranslations.Add(profTrans1);
                    }

                    _db.SaveChanges();

                    profile.Id = profil.Id;
                    string roleId = ((int)GeneralEnums.Role.User).ToString();
                    // var userProfile = _db.UserProfiles.Find(UserId);
                    var aspUser = _db.AspNetUsers.FirstOrDefault(r => r.UserName == profil.Username);
                    if (!_db.AspNetUserRoles.Any(r => r.UserId == aspUser.Id && r.RoleId == roleId))
                    {
                        _db.AspNetUserRoles.Add(new AspNetUserRole()
                        {
                            RoleId = roleId,
                            UserId = aspUser.Id
                        });
                        _db.SaveChanges();
                    }
                    return(Json(profile, JsonRequestBehavior.AllowGet));
                }
                catch (Exception ex)
                {
                    LogHelper.LogException(User.Identity.Name, ex, "Error While adding new profile");
                    UserManager.Delete(user);
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
コード例 #4
0
ファイル: AccountController.cs プロジェクト: FirasOmar/LeadMS
        public IHttpActionResult UpdateProfile(ProfileViewModel registerModel)
        {
            AuthenticationHelper.ApiAuthorizationCheck(Request);
            try
            {
                var lang       = Request?.Headers?.AcceptLanguage?.FirstOrDefault()?.Value ?? "ar";
                var languageId = lang == "ar"
                    ? (int)GeneralEnums.LanguageEnum.Arabic
                    : (int)GeneralEnums.LanguageEnum.English;


                var city          = LookupHelper.GetLookupDetailsByCode(registerModel.CityCode)?.Id;
                var gender        = LookupHelper.GetLookupDetailsByCode(registerModel.GenderCode)?.Id;
                var martialStatus = LookupHelper.GetLookupDetailsByCode(registerModel.MartialStatusCode)?.Id;
                var province      = LookupHelper.GetLookupDetailsByCode(registerModel.ProvinceCode)?.Id;


                var userProfile = _db.UserProfiles.FirstOrDefault(r => r.Username == registerModel.Username);
                if (userProfile != null)
                {
                    userProfile.Email                 = registerModel.Email.IsNullOrWhiteSpace() ? userProfile.Email : registerModel.Email;
                    userProfile.Fax                   = registerModel.Fax.IsNullOrWhiteSpace() ? userProfile.Fax : registerModel.Fax;
                    userProfile.IdNumber              = registerModel.IdNumber.IsNullOrWhiteSpace() ? userProfile.IdNumber : registerModel.IdNumber;
                    userProfile.Mobile                = registerModel.Mobile.IsNullOrWhiteSpace() ? userProfile.Mobile : registerModel.Mobile;
                    userProfile.PreferedLanguageId    = registerModel.PrefferdLanguage ?? userProfile.PreferedLanguageId;
                    userProfile.CityId                = city ?? userProfile.CityId;
                    userProfile.DepartmentId          = registerModel.Department ?? userProfile.DepartmentId;
                    userProfile.GenderLookupId        = gender ?? userProfile.GenderLookupId;
                    userProfile.MartialStatusLookupId = martialStatus ?? userProfile.MartialStatusLookupId;
                    userProfile.ProvinceId            = province ?? userProfile.ProvinceId;
                    userProfile.RegionId              = registerModel.RegionId ?? userProfile.RegionId;
                    userProfile.Birthday              = registerModel.BirthDay ?? userProfile.Birthday;
                    userProfile.PhoneNumber           = registerModel.PhoneNumber.IsNullOrWhiteSpace() ? userProfile.PhoneNumber : registerModel.PhoneNumber;
                    userProfile.ProfilePhoto          = registerModel.ProfilePath.IsNullOrWhiteSpace() ? userProfile.ProfilePhoto : registerModel.ProfilePath;
                    var userProfileTrans =
                        _db.UserProfileTranslations.FirstOrDefault(r =>
                                                                   r.UserProfileId == userProfile.Id && r.LanguageId == languageId) ??
                        _db.UserProfileTranslations.FirstOrDefault(r => r.UserProfileId == userProfile.Id);
                    if (userProfileTrans != null)
                    {
                        userProfileTrans.FullName = registerModel.FullName.IsNullOrWhiteSpace()
                            ? userProfileTrans.FullName
                            : registerModel.FullName;
                        userProfileTrans.Address = registerModel.Address.IsNullOrWhiteSpace()
                            ? userProfileTrans.Address
                            : registerModel.Address;
                        _db.Entry(userProfileTrans).State = EntityState.Modified;
                    }
                    _db.Entry(userProfile).State = EntityState.Modified;
                    _db.SaveChanges();
                    if (!registerModel.Password.IsNullOrWhiteSpace())
                    {
                        var user = _db.AspNetUsers.FirstOrDefault(r => r.UserName == registerModel.Username);
                        if (user != null)
                        {
                            UserManager.RemovePassword(user.Id);
                            var updateResult = UserManager.AddPassword(user.Id, registerModel.Password);
                            if (updateResult.Succeeded)
                            {
                                return(Ok(registerModel));
                            }
                        }
                    }
                    else
                    {
                        return(Ok(registerModel));
                    }
                    return(Content(HttpStatusCode.Forbidden, new BaseApiResponse()
                    {
                        StatusCode = HttpStatusCode.Forbidden,
                        Message = "General Error"
                    }));
                }
                else
                {
                    var user = new ApplicationUser {
                        UserName = registerModel.Username, Email = registerModel.Email
                    };
                    var result = UserManager.CreateAsync(user, registerModel.Password);
                    if (result.Result.Succeeded)
                    {
                        var profil = new UserProfile
                        {
                            Fax                   = registerModel.Fax ?? string.Empty,
                            Birthday              = registerModel.BirthDay,
                            CreatedOn             = DateTime.Now,
                            GenderLookupId        = gender,
                            ProvinceId            = province,
                            CityId                = city,
                            RegionId              = registerModel.RegionId,
                            IdNumber              = registerModel.IdNumber ?? string.Empty,
                            PhoneNumber           = registerModel.PhoneNumber ?? string.Empty,
                            Mobile                = registerModel.Mobile ?? string.Empty,
                            MartialStatusLookupId = martialStatus,
                            ManagerId             = registerModel.ManagerId,
                            DepartmentId          = registerModel.Department,
                            PreferedLanguageId    = registerModel.PrefferdLanguage,
                            Status                = (int)GeneralEnums.StatusEnum.Active,
                            Username              = registerModel.Username,
                            Email                 = registerModel.Email
                        };
                        _db.UserProfiles.Add(profil);
                        _db.SaveChanges();

                        var profTrans = new UserProfileTranslation()
                        {
                            Address       = registerModel.Address ?? string.Empty,
                            FullName      = registerModel.FullName,
                            IsDefault     = languageId == CultureHelper.GetDefaultLanguageId(),
                            LanguageId    = languageId,
                            UserProfileId = profil.Id
                        };
                        _db.UserProfileTranslations.Add(profTrans);
                        if (!profTrans.IsDefault)
                        {
                            var profTrans1 = new UserProfileTranslation()
                            {
                                Address       = registerModel.Address ?? string.Empty,
                                FullName      = registerModel.FullName,
                                IsDefault     = true,
                                LanguageId    = CultureHelper.GetDefaultLanguageId(),
                                UserProfileId = profil.Id
                            };
                            _db.UserProfileTranslations.Add(profTrans1);
                        }

                        _db.SaveChanges();
                        registerModel.Id = profil.Id;
                        return(Ok(registerModel));
                    }
                    else
                    {
                        return(Content(HttpStatusCode.Forbidden, new BaseApiResponse()
                        {
                            StatusCode = HttpStatusCode.Forbidden,
                            Message = result.Result.Errors.FirstOrDefault()
                        }));
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.LogException(Core.Constants.Users.System, ex, Core.Constants.Errors.Apis.ErrorRegister);
                return(Content(HttpStatusCode.InternalServerError, new BaseApiResponse()
                {
                    StatusCode = HttpStatusCode.InternalServerError,
                    Message = Core.Constants.Errors.Apis.ErrorRegister
                }));
            }
        }
コード例 #5
0
ファイル: AccountController.cs プロジェクト: FirasOmar/LeadMS
        public IHttpActionResult Register(ProfileViewModel registerModel)
        {
            AuthenticationHelper.ApiAuthorizationCheck(Request);
            try
            {
                var lang       = Request?.Headers?.AcceptLanguage?.FirstOrDefault()?.Value ?? "ar";
                var languageId = lang == "ar"
                    ? (int)GeneralEnums.LanguageEnum.Arabic
                    : (int)GeneralEnums.LanguageEnum.English;

                var user = new ApplicationUser {
                    UserName = registerModel.Username, Email = registerModel.Email
                };
                var result = UserManager.CreateAsync(user, registerModel.Password);
                if (result.Result.Succeeded)
                {
                    var roleId = _db.AspNetRoles.FirstOrDefault(r => r.Name == Core.Constants.Roles.Citizen)?.Id;
                    if (roleId != null)
                    {
                        _db.AspNetUserRoles.Add(new AspNetUserRole()
                        {
                            RoleId = roleId,
                            UserId = user.Id
                        });
                        _db.SaveChanges();
                    }

                    var city          = LookupHelper.GetLookupDetailsByCode(registerModel.CityCode)?.Id;
                    var gender        = LookupHelper.GetLookupDetailsByCode(registerModel.GenderCode)?.Id;
                    var martialStatus = LookupHelper.GetLookupDetailsByCode(registerModel.MartialStatusCode)?.Id;
                    var province      = LookupHelper.GetLookupDetailsByCode(registerModel.ProvinceCode)?.Id;

                    var profil = new UserProfile
                    {
                        Fax                   = registerModel.Fax ?? string.Empty,
                        Birthday              = registerModel.BirthDay,
                        CreatedOn             = DateTime.Now,
                        GenderLookupId        = gender,
                        ProvinceId            = province,
                        CityId                = city,
                        RegionId              = registerModel.RegionId,
                        IdNumber              = registerModel.IdNumber ?? string.Empty,
                        PhoneNumber           = registerModel.PhoneNumber ?? string.Empty,
                        Mobile                = registerModel.Mobile ?? string.Empty,
                        MartialStatusLookupId = martialStatus,
                        ManagerId             = registerModel.ManagerId,
                        DepartmentId          = registerModel.Department,
                        PreferedLanguageId    = registerModel.PrefferdLanguage,
                        Status                = (int)GeneralEnums.StatusEnum.Active,
                        Username              = registerModel.Username,
                        Email                 = registerModel.Email
                    };
                    _db.UserProfiles.Add(profil);
                    _db.SaveChanges();

                    var profTrans = new UserProfileTranslation()
                    {
                        Address       = registerModel.Address ?? string.Empty,
                        FullName      = registerModel.FullName,
                        IsDefault     = languageId == CultureHelper.GetDefaultLanguageId(),
                        LanguageId    = languageId,
                        UserProfileId = profil.Id
                    };
                    _db.UserProfileTranslations.Add(profTrans);
                    if (!profTrans.IsDefault)
                    {
                        var profTrans1 = new UserProfileTranslation()
                        {
                            Address       = registerModel.Address ?? string.Empty,
                            FullName      = registerModel.FullName,
                            IsDefault     = true,
                            LanguageId    = CultureHelper.GetDefaultLanguageId(),
                            UserProfileId = profil.Id
                        };
                        _db.UserProfileTranslations.Add(profTrans1);
                    }

                    _db.SaveChanges();
                    registerModel.Id = profil.Id;
                    return(Ok(registerModel));
                }
                else
                {
                    return(Content(HttpStatusCode.Forbidden, new BaseApiResponse()
                    {
                        StatusCode = HttpStatusCode.Forbidden,
                        Message = result.Result.Errors.FirstOrDefault()
                    }));
                }
            }
            catch (Exception ex)
            {
                LogHelper.LogException(Core.Constants.Users.System, ex, Core.Constants.Errors.Apis.ErrorRegister);
                return(Content(HttpStatusCode.InternalServerError, new BaseApiResponse()
                {
                    StatusCode = HttpStatusCode.InternalServerError,
                    Message = Core.Constants.Errors.Apis.ErrorRegister
                }));
            }
        }
コード例 #6
0
ファイル: AccountController.cs プロジェクト: FirasOmar/LeadMS
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Manage"));
            }
            if (ModelState.IsValid)
            {
                int    languageId = CultureHelper.GetCurrentLanguageId(Request.Cookies["_culture"]);
                string customerId = null;

                var account = _db.UserProfiles.FirstOrDefault(r => r.Username == model.Email && r.Status != (int)GeneralEnums.StatusEnum.Deleted);
                if (account != null && account.Status == (int)GeneralEnums.StatusEnum.Deactive)
                {
                    ModelState.AddModelError("", "البريد الالكتروني غير فعّال , يرجى مراجعه المسؤول لتفعيل حسابك");
                }
                else
                {
                    var user = new ApplicationUser {
                        UserName = model.Email, Email = model.Email
                    };
                    var result = await UserManager.CreateAsync(user, model.Password);

                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                        try
                        {
                            var companyObj = new Company()
                            {
                                Name = model.CompanyName
                            };
                            _db.Companies.Add(companyObj);
                            _db.SaveChanges();



                            var userProfile = new UserProfile
                            {
                                Birthday              = model.BirthDay,
                                CreatedOn             = DateTime.Now,
                                Fax                   = model.Fax ?? string.Empty,
                                GenderLookupId        = model.GenderLookupId,
                                IdNumber              = model.IdNumber ?? string.Empty,
                                MartialStatusLookupId = model.MartialStatusLookupId,
                                PhoneNumber           = model.PhoneNumber ?? string.Empty,
                                Mobile                = model.Mobile ?? string.Empty,
                                Status                = (int)AccountEnums.AccountStatusEnum.Active,
                                Username              = user.UserName,
                                ProvinceId            = model.ProvinceId,
                                RegionId              = model.RegionId,
                                CityId                = model.CityId,
                                PreferedLanguageId    = model.PrefferdLanguage,
                                Email                 = model.Email,
                                CompanyId             = companyObj.Id,
                            };
                            _db.UserProfiles.Add(userProfile);
                            _db.SaveChanges();


                            var userProfileTrans = new UserProfileTranslation()
                            {
                                FullName      = model.FullName,
                                Address       = model.Address ?? string.Empty,
                                IsDefault     = languageId == (int)GeneralEnums.LanguageEnum.Arabic,
                                LanguageId    = languageId,
                                UserProfileId = userProfile.Id
                            };

                            _db.UserProfileTranslations.Add(userProfileTrans);
                            if (!userProfileTrans.IsDefault)
                            {
                                var userProfileTrans1 = new UserProfileTranslation()
                                {
                                    FullName      = model.FullName,
                                    Address       = model.Address ?? string.Empty,
                                    IsDefault     = true,
                                    LanguageId    = CultureHelper.GetDefaultLanguageId(),
                                    UserProfileId = userProfile.Id
                                };
                                _db.UserProfileTranslations.Add(userProfileTrans1);
                            }
                            _db.SaveChanges();


                            SessionHelper.SetCompanyId(companyObj.Id);
                            string roleId = "5";
                            // var userProfile = _db.UserProfiles.Find(UserId);
                            var aspUser = _db.AspNetUsers.FirstOrDefault(r => r.UserName == userProfile.Username);
                            if (!_db.AspNetUserRoles.Any(r => r.UserId == aspUser.Id && r.RoleId == roleId))
                            {
                                _db.AspNetUserRoles.Add(new AspNetUserRole()
                                {
                                    RoleId = roleId,
                                    UserId = aspUser.Id
                                });
                                _db.SaveChanges();
                            }
                        }
                        catch (Exception ex)
                        {
                            LogHelper.LogException(User.Identity.Name, ex, "Error While register new user!");
                            UserManager.Delete(user);
                        }
                        // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                        // Send an email with this link
                        string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                        var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                        await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");



                        return(RedirectToAction("Index", "Home"));
                    }
                    AddErrors(result);
                }
            }
            ViewBag.GenderLookupId = new SelectList(LookupHelper.GetLookupDetailsByMasterId((int)GeneralEnums.MasterLookupEnums.Gender, Request.Cookies["_culture"]), "Id", "Name", model.GenderLookupId);
            //ViewBag.MartialStatusLookupId = new SelectList(LookupHelper.GetLookupDetailsByMasterId((int)GeneralEnums.MasterLookupEnums.MartialStatus, Request.Cookies["_culture"]), "Id", "Name", model.MartialStatusLookupId);
            //ViewBag.ProvinceId = new SelectList(LookupHelper.GetLookupDetailsByMasterId((int)GeneralEnums.MasterLookupEnums.Province, Request.Cookies["_culture"]), "Id", "Name", model.ProvinceId);
            //ViewBag.RegionId = new SelectList(LookupHelper.GetLookupDetailsByMasterId((int)GeneralEnums.MasterLookupEnums.Region, Request.Cookies["_culture"]), "Id", "Name", model.RegionId);
            //ViewBag.CityId = new SelectList(LookupHelper.GetLookupDetailsByMasterId((int)GeneralEnums.MasterLookupEnums.City, Request.Cookies["_culture"]), "Id", "Name", model.CityId);
            var prefferdLanguage = LookupHelper.GetLookupDetailsByMasterId((int)GeneralEnums.MasterLookupEnums.PrefferdLanguage,
                                                                           Request.Cookies["_culture"]);

            ViewBag.PrefferdLanguage = new SelectList(prefferdLanguage, "Id", "Name", model.PrefferdLanguage);
            // If we got this far, something failed, redisplay form
            return(View(model));
        }