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));
        }
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var langId  = CultureHelper.GetCurrentLanguageId(Request.Cookies["_culture"]);
            var profile = LanguageFallbackHelper.GetUserProfile((int)id, langId);

            if (profile == null || profile.Status == (int)GeneralEnums.StatusEnum.Deleted)
            {
                return(HttpNotFound());
            }

            var systemCases = _db.SystemCases.Where(x => x.CreatedBy == profile.Username).ToList().Where(x => x.CreatedBy == profile.Username).ToList().Select(x => new CaseViewModel
            {
                Id           = x.Id,
                Status       = x.Status,
                Description  = x.Description,
                CreatedOn    = x.CreatedOn,
                DeletedOn    = x.DeletedOn,
                CreatedBy    = x.CreatedBy,
                Tags         = x.Tags,
                Title        = x.Title,
                Address      = x.Address,
                Location     = x.Location,
                TypeId       = x.TypeId,
                AssigneeId   = x.AssigneeId,
                AssigneeName = x.AssigneeId != null ?
                               LanguageFallbackHelper.GetUserProfile((int)x.AssigneeId, langId)?.FullName ??
                               string.Empty : string.Empty,
                CategoryId   = x.CategoryId,
                CategoryName = x.CategoryId != null ? LookupHelper.GetLookupDetailsById((int)x.CategoryId, Request.Cookies["_culture"])?.Name ?? string.Empty : string.Empty,
                PriorityId   = x.PriorityId,
                PriorityName = x.PriorityId != null ? LookupHelper.GetLookupDetailsById((int)x.PriorityId, Request.Cookies["_culture"])?.Name ?? string.Empty : string.Empty,
                SeverityId   = x.SeverityId,
                SeverityName = x.SeverityId != null ? LookupHelper.GetLookupDetailsById((int)x.SeverityId, Request.Cookies["_culture"])?.Name ?? string.Empty : string.Empty,
                UniqueId     = x.UniqueId
            }).ToList();

            var result = new CitizenProfileViewModel()
            {
                Status                  = profile.Status,
                Address                 = profile.Address,
                Id                      = profile.Id,
                ManagerId               = profile.ManagerId,
                Department              = profile.Department,
                PrefferdLanguage        = profile.PrefferdLanguage,
                Username                = profile.Username,
                FullName                = profile.FullName,
                Email                   = profile.Email,
                WeekDaysOff             = profile.WeekDaysOff,
                LanguageId              = profile.LanguageId,
                LastLogin               = profile.LastLogin,
                CityId                  = profile.CityId,
                ManagerName             = profile.ManagerName,
                UserHolidays            = profile.UserHolidays,
                Password                = profile.Password,
                DepartmentName          = profile.DepartmentName,
                IdNumber                = profile.IdNumber,
                BirthDay                = profile.BirthDay,
                CityCode                = profile.CityCode,
                CityName                = profile.CityName,
                ConfirmPassword         = profile.ConfirmPassword,
                CustomerId              = profile.CustomerId,
                Fax                     = profile.Fax,
                GenderCode              = profile.GenderCode,
                GenderLookupId          = profile.GenderLookupId,
                GenderLookupName        = profile.GenderLookupName,
                MartialStatusCode       = profile.MartialStatusCode,
                MartialStatusLookupId   = profile.MartialStatusLookupId,
                MartialStatusLookupName = profile.MartialStatusLookupName,
                Mobile                  = profile.Mobile,
                PhoneNumber             = profile.PhoneNumber,
                PrefferdLanguageName    = profile.PrefferdLanguageName,
                ProfilePath             = profile.ProfilePath,
                ProvinceCode            = profile.ProvinceCode,
                ProvinceId              = profile.ProvinceId,
                ProvinceName            = profile.ProvinceName,
                RegionId                = profile.RegionId,
                RegionName              = profile.RegionName,
                Roles                   = profile.Roles,
                Cases                   = systemCases
            };
            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(result));
        }