public void Allocate_Should_Return_Null_When_InValid_CampaignTestKey_Is_Provided() { var mockUserHasher = MockUserHasher.Get(); var campaignResolver = GetCampaignResolver(mockUserHasher); UserProfileMap userProfileMap = null; var selectedCampaign = campaignResolver.Allocate(GetAccountSettings(status: "RUNNING"), userProfileMap, MockCampaignTestKey + MockCampaignTestKey, MockUserId); Assert.Null(selectedCampaign); mockUserHasher.Verify(mock => mock.ComputeBucketValue(It.IsAny <string>(), It.IsAny <double>(), It.IsAny <double>()), Times.Never); }
public void Allocate_Should_Return_Null_When_Valid_UserProfileMap_With_Valid_Campaign_Is_Given_And_Campaign_Is_Not_Running() { var mockUserHasher = MockUserHasher.Get(); var campaignResolver = GetCampaignResolver(mockUserHasher); UserProfileMap userProfileMap = new UserProfileMap(MockUserId, MockCampaignTestKey, MockVariationName); var selectedCampaign = campaignResolver.Allocate(GetAccountSettings(status: "NOT_RUNNING"), userProfileMap, MockCampaignTestKey, MockUserId); Assert.Null(selectedCampaign); mockUserHasher.Verify(mock => mock.ComputeBucketValue(It.IsAny <string>(), It.IsAny <double>(), It.IsAny <double>()), Times.Never); }
public ActionResult AjaxGetProfileById(int Id) { UserProfileModel objProfile = UserProfileMap.Map(_repoUserProfile.GetSingle(x => x.Id == Id)); List <DisciplineModel> lstDiscipline = new List <DisciplineModel>(); lstDiscipline = DisciplineMap.Map(_repoDiscipline.GetList(x => x.CategoryId == objProfile.CategoryId).ToList()); List <ProvinceModel> lstProvince = new List <ProvinceModel>(); lstProvince = ProvinceMap.Map(_repoProvince.GetList(x => x.Country == objProfile.CountryName).ToList()); return(Json(new { status = "success", profile = objProfile, lstDiscipline = lstDiscipline.ToArray(), lstProvince = lstProvince.ToArray() })); }
public void Allocate_Should_Not_Compute_Hash_When_Valid_UserProfileMap_With_Valid_Variation_Is_Given() { var mockUserHasher = MockUserHasher.Get(); VariationAllocator variationResolver = GetVariationResolver(mockUserHasher); UserProfileMap userProfileMap = new UserProfileMap(MockUserId, MockCampaignTestKey, MockVariationName); var selectedVariation = variationResolver.Allocate(userProfileMap, GetCampaign(MockCampaignTestKey), MockUserId); Assert.NotNull(selectedVariation); Assert.Equal(MockVariationName, selectedVariation.Name); mockUserHasher.Verify(mock => mock.ComputeBucketValue(It.IsAny <string>(), It.IsAny <double>(), It.IsAny <double>()), Times.Never); }
public async Task <UserProfileModel> Lock(Guid userId) { var user = await usersRepository.GetQuery().FirstOrDefaultAsync(x => x.Id == userId); if (user != null) { user.IsLocked = true; await dataContext.SaveChangesAsync(); } return(UserProfileMap.Map(user)); }
public async Task <UserProfileModel> Unlock(Guid userId) { var user = await usersRepository.GetQuery().FirstOrDefaultAsync(x => x.Id == userId); if (user != null) { user.IsLocked = false; user.CountOfInvalidAttempts = 0; await dataContext.SaveChangesAsync(); } return(UserProfileMap.Map(user)); }
protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); if (builder == null) { throw new ArgumentNullException(nameof(builder), $"Cannot create Context Model with a null {nameof(ModelBuilder)}."); } UserMap.Map(builder.Entity <User>()); UserProfileMap.Map(builder.Entity <UserProfile>()); MapTableNames(builder); }
public async Task <UserProfileModel> AddRole(Guid userId, Role role) { var user = await usersRepository.GetQuery().FirstOrDefaultAsync(x => x.Id == userId); if (user != null && !user.UserRoles.Any(x => x.Role == role)) { user.UserRoles.Add(new UserRole { Role = role }); await dataContext.SaveChangesAsync(); } return(UserProfileMap.Map(user)); }
public void Allocate_Should_Return_Null_Audience_Condition_Not_Met() { var mockUserHasher = Mock.GetUserHasher(); Mock.SetupCompute(mockUserHasher, returnVal: 80); CampaignAllocator campaignResolver = GetCampaignResolver(mockUserHasher); UserProfileMap userProfileMap = null; var selectedCampaign = campaignResolver.Allocate(GetAccountSettings(), userProfileMap, MockCampaignTestKey, MockUserId); Assert.Null(selectedCampaign); mockUserHasher.Verify(mock => mock.ComputeBucketValue(It.IsAny <string>(), It.IsAny <double>(), It.IsAny <double>()), Times.Once); mockUserHasher.Verify(mock => mock.ComputeBucketValue(It.Is <string>((val) => MockUserId.Equals(val)), It.Is <double>((val) => 100 == val), It.Is <double>(val => 1 == val)), Times.Once); }
public ActionResult Profile() { UserProfileModel objUserProfile = new UserProfileModel(); //_repoFile.GetList(x=>x. if (CurrentRole != "Administrator") { var objProfile = _repoUserProfile.GetSingle(x => x.UserId == CurrentUser.UserId); if (objProfile != null) { ViewBag.DisciplineId = new SelectList(_repoDiscipline.GetList(x => x.CategoryId == objProfile.CategoryId).ToList(), "Id", "DisciplineName", objProfile.DisciplineId); ViewBag.ProvinceId = new SelectList(_repoProvince.GetList(x => x.Country == objProfile.CountryName).ToList(), "Id", "Name_1", objProfile.StateId); objUserProfile = UserProfileMap.Map(objProfile); objUserProfile.IsNew = false; var objEntityFile = _repoEntityFile.GetSingle(x => x.EntityId == objProfile.Id && x.SectionId == 1); if (objEntityFile != null) { objUserProfile.FileId = objEntityFile.FileId.GetValueOrDefault(); } } else { objUserProfile.IsNew = true; } } else { var objProfile = _repoUserProfile.GetSingle(x => x.UserId == CurrentUser.UserId); if (objProfile == null) ////This condition is to check if user has a profile or not { objUserProfile.IsNew = true; } List <UserProfileModel> lstUserProfile = UserProfileMap.Map(_repoUserProfile.GetList(x => x.StatusId == 0).ToList()); ViewBag.TotalUserList = lstUserProfile.Count; } ViewBag.CurrentMainTab = "Home"; ViewBag.CurrentSubTab = "ControlPanel"; ViewBag.CurrentSuperSubTab = "Profile"; ProfileSearchModel objProfileSearch = new ProfileSearchModel(); objUserProfile.ProfileSearch = objProfileSearch; return(View(objUserProfile)); }
public void Allocate_Should_Compute_Hash_When_UserProfileMap_Is_Null() { var mockUserHasher = Mock.GetUserHasher(); Mock.SetupComputeBucketValue(mockUserHasher, returnVal: 10, outHashValue: 1234567); VariationAllocator variationResolver = GetVariationResolver(mockUserHasher); UserProfileMap userProfileMap = null; var selectedVariation = variationResolver.Allocate(userProfileMap, GetCampaign(MockCampaignTestKey), MockUserId); Assert.NotNull(selectedVariation); Assert.Equal(MockVariationName, selectedVariation.Name); mockUserHasher.Verify(mock => mock.ComputeBucketValue(It.IsAny <string>(), It.IsAny <double>(), It.IsAny <double>()), Times.Once); mockUserHasher.Verify(mock => mock.ComputeBucketValue(It.Is <string>((val) => MockUserId.Equals(val)), It.Is <double>((val) => 10000 == val), It.Is <double>(val => 1 == val)), Times.Once); }
public async Task <UserProfileModel> RemoveRole(Guid userId, Role role) { var user = await usersRepository.GetQuery().FirstOrDefaultAsync(x => x.Id == userId); if (user != null) { var userRoles = user.UserRoles.Where(x => x.Role == role).ToList(); foreach (var userRole in userRoles) { userRolesRepository.Remove(userRole); } await dataContext.SaveChangesAsync(); } return(UserProfileMap.Map(user)); }
/// <summary> /// Allocate Variation by checking previously assigned variation if userProfileMap is provided, else by computing User Hash and matching it in bucket for eligible variation. /// </summary> /// <param name="userProfileMap"></param> /// <param name="campaign"></param> /// <param name="userId"></param> /// <returns></returns> public Variation Allocate(UserProfileMap userProfileMap, BucketedCampaign campaign, string userId) { if (campaign == null) { return(null); } if (userProfileMap == null) { double maxVal = Constants.Variation.MAX_TRAFFIC_VALUE; double multiplier = maxVal / campaign.PercentTraffic / 100; ///This is to evenly spread all user among variations. var bucketValue = this._userHasher.ComputeBucketValue(userId, maxVal, multiplier, out double hashValue); var selectedVariation = campaign.Variations.Find(bucketValue); LogDebugMessage.VariationHashBucketValue(file, userId, campaign.Key, campaign.PercentTraffic, hashValue, bucketValue); return(selectedVariation); } return(campaign.Variations.Find(userProfileMap.VariationName, GetVariationName)); }
public ActionResult ViewProfile(long?id) { ViewBag.CurrentMainTab = "Front"; ViewBag.CurrentSubTab = "Profile"; ViewBag.CurrentSuperSubTab = "Name"; var objUser = _repoUserProfile.GetSingle(x => x.Id == id); UserProfileModel objUserProfile = UserProfileMap.Map(objUser); var objEntityFile = _repoEntityFile.GetSingle(x => x.EntityId == objUserProfile.Id && x.Section.SectionName == "Users"); if (objEntityFile != null) { objUserProfile.FileId = objEntityFile.FileId; } objUserProfile.Email = Membership.GetUser(objUser.UserId).Email; objUserProfile.Age = DateTime.Now.Year - objUserProfile.BirthDate.Year; return(View(objUserProfile)); }
/// <summary> /// Allocate variation by checking UserProfileService, Campaign Traffic Allocation and compute UserHash to check variation allocation by bucketing. /// </summary> /// <param name="campaignTestKey"></param> /// <param name="userId"></param> /// <returns> /// If Variation is allocated, returns UserAssignedInfo with valid details, else return Empty UserAssignedInfo. /// </returns> private UserAllocationInfo AllocateVariation(string campaignTestKey, string userId, string apiName = null) { UserProfileMap userProfileMap = this._userProfileService.GetUserMap(campaignTestKey, userId); BucketedCampaign selectedCampaign = this._campaignAllocator.Allocate(this._settings, userProfileMap, campaignTestKey, userId, apiName); if (selectedCampaign != null) { Variation variation = this._variationAllocator.Allocate(userProfileMap, selectedCampaign, userId); if (variation != null) { LogInfoMessage.VariationAllocated(file, userId, campaignTestKey, variation.Name); LogDebugMessage.GotVariationForUser(file, userId, campaignTestKey, variation.Name, nameof(AllocateVariation)); this._userProfileService.SaveUserMap(userId, selectedCampaign.Key, variation.Name); return(new UserAllocationInfo(variation, selectedCampaign)); } } LogInfoMessage.NoVariationAllocated(file, userId, campaignTestKey); return(new UserAllocationInfo()); }
internal static void SetupLookup(Mock <IUserProfileService> mockUserProfileService, UserProfileMap returnValue) { mockUserProfileService.Setup(mock => mock.Lookup(It.IsAny <string>(), It.IsAny <string>())) .Returns(returnValue); }
internal static void SetupLookup(Mock <IUserProfileService> mockUserProfileService, UserProfileMap returnValue) { MockUserProfileService.SetupLookup(mockUserProfileService, returnValue); }
public PartialViewResult UserList(string name, string countryName, int?provinceId, int?disciplineId, string sex, int?categoryId, int?sortOrder, int?pageNumber = null, int?itemsPerPage = null) { int listCount = 0; int offset = 0; offset = (((int)pageNumber - 1) * (int)itemsPerPage); List <UserProfileModel> lstUserProfile = new List <UserProfileModel>(); List <UserProfileModel> lstNewUserProfileModel = new List <UserProfileModel>(); if (sortOrder == 1) { lstUserProfile = UserProfileMap.Map(_repoUserProfile.GetList(x => x.IsLeonniTeam == true).OrderBy(x => x.FirstName).Skip(offset).Take((int)itemsPerPage).ToList()); listCount = _repoUserProfile.GetList().ToList().Count; } else if (sortOrder == 2) { lstUserProfile = UserProfileMap.Map(_repoUserProfile.GetList(x => x.IsLeonniTeam == true).OrderByDescending(x => x.FirstName).Skip(offset).Take((int)itemsPerPage).ToList()); listCount = _repoUserProfile.GetList().ToList().Count; } else { lstUserProfile = UserProfileMap.Map(_repoUserProfile.GetList(x => x.IsLeonniTeam == true).OrderBy(x => x.FirstName).Skip(offset).Take((int)itemsPerPage).ToList()); listCount = _repoUserProfile.GetList().ToList().Count; } if (categoryId != null) { if (categoryId != 0) { lstUserProfile = lstUserProfile.Where(x => x.CategoryId == categoryId).ToList(); listCount = _repoUserProfile.GetList(x => x.CategoryId == categoryId).ToList().Count; } } if (!string.IsNullOrEmpty(sex)) { if (sex != "Sex") { lstUserProfile = lstUserProfile.Where(x => x.Sex == sex).ToList(); listCount = _repoUserProfile.GetList(x => x.Sex == sex).ToList().Count; } } if (disciplineId != null) { if (disciplineId != 0) { lstUserProfile = lstUserProfile.Where(x => x.DisciplineId == disciplineId).ToList(); listCount = _repoUserProfile.GetList(x => x.DisciplineId == disciplineId).ToList().Count; } } if (!string.IsNullOrEmpty(countryName)) { if (countryName != "Country") { lstUserProfile = lstUserProfile.Where(x => x.CountryName == countryName).ToList(); listCount = _repoUserProfile.GetList(x => x.CountryName == countryName).ToList().Count; } } if (provinceId != null) { if (provinceId != 0) { lstUserProfile = lstUserProfile.Where(x => x.StateId == provinceId).ToList(); listCount = _repoUserProfile.GetList(x => x.StateId == provinceId).ToList().Count; } } if (!string.IsNullOrEmpty(name)) { lstUserProfile = lstUserProfile.Where(x => x.FirstName == name).ToList(); listCount = _repoUserProfile.GetList(x => x.FirstName == name).ToList().Count; } foreach (var item in lstUserProfile.ToList()) { var objEntityFile = _repoEntityFile.GetSingle(x => x.EntityId == item.Id && x.Section.SectionName == "profile"); if (objEntityFile != null) { item.FileId = objEntityFile.FileId; } lstNewUserProfileModel.Add(item); } ViewBag.PagedListofUsers = lstNewUserProfileModel ?? new List <UserProfileModel>(); ViewBag.TotalUserCount = listCount; return(PartialView("_UsersList", lstNewUserProfileModel)); }
/// <summary> /// Allocate Campaign based on userProfileMap, of if userProfileMap is not present based on trafficAllocation. /// </summary> /// <param name="userId"></param> /// <param name="campaignTestKey"></param> /// <param name="userProfileMap"></param> /// <param name="requestedCampaign"></param> /// <returns></returns> private BucketedCampaign AllocateCampaign(string userId, string campaignTestKey, UserProfileMap userProfileMap, BucketedCampaign requestedCampaign) { BucketedCampaign allocatedCampaign = null; LogDebugMessage.CheckUserEligibilityForCampaign(file, campaignTestKey, requestedCampaign.PercentTraffic, userId); if (userProfileMap == null) { allocatedCampaign = AllocateByTrafficAllocation(userId, requestedCampaign); } else if (userProfileMap.CampaignTestKey.Equals(requestedCampaign.Key)) { allocatedCampaign = requestedCampaign; } return(allocatedCampaign); }
public async Task <UserProfileModel> GetProfile(Guid id) { var user = await usersRepository.GetQuery().FirstOrDefaultAsync(x => x.Id == id); return(UserProfileMap.Map(user)); }
protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); var userMap = new UserMap(modelBuilder.Entity <User>()); var userProfileMap = new UserProfileMap(modelBuilder.Entity <UserProfile>()); }
public ActionResult Groups(GroupModel objGroup) { ViewBag.DisciplineId = new SelectList(_repoDiscipline.GetList().ToList(), "Id", "DisciplineName", ""); if (objGroup.DisciplineId == 0) { TempData[LeonniConstants.ErrorMessage] = " Please Select Any Discipline"; return(View(objGroup)); } else if (objGroup.CountryName == "Country") { TempData[LeonniConstants.ErrorMessage] = " Please Select Any Country"; return(View(objGroup)); } if (objGroup.ProvinceId == 0) { TempData[LeonniConstants.ErrorMessage] = " Please Select Any State"; return(View(objGroup)); } else { try { Group newGroup = null; if (ModelState.IsValid) { if (objGroup != null) { if (objGroup.IsNew == true) { objGroup.CreatedDate = DateTime.Now; if (_repoUserProfile != null) { objGroup.CreatedBy = _repoUserProfile.GetSingle(x => x.UserId == CurrentUser.UserId).Id; } objGroup.IsDeleted = false; objGroup.Status = (int)Status.Active; objGroup.UserProfile = UserProfileMap.Map(_repoUserProfile.GetSingle(x => x.UserId == CurrentUser.UserId)); newGroup = GroupMap.Map(objGroup); _repoGroup.Add(newGroup); objGroup.IsNew = false; } else { if (objGroup.GroupPic != null) { var entityFileModel = _repoEntityFile.GetSingle(x => x.SectionId == 2 && x.EntityId == objGroup.Id); if (entityFileModel != null) { var fileModel = _repoFile.GetSingle(x => x.Id == entityFileModel.FileId); if (fileModel != null) { _repoFile.Delete(fileModel); _repoFile.Save(); } _repoEntityFile.Delete(entityFileModel); _repoEntityFile.Save(); } } objGroup.IsDeleted = false; objGroup.Status = (int)Status.Active; _repoGroup.Update(GroupMap.Map(objGroup)); } _repoGroup.Save(); if (objGroup.GroupPic != null && objGroup.GroupPic.InputStream != null) { var file = new Models.File(); file.ContentType = objGroup.GroupPic.ContentType; file.FileName = objGroup.GroupPic.FileName; var memoryStream = new MemoryStream(); objGroup.GroupPic.InputStream.CopyTo(memoryStream); file.Content = memoryStream.ToArray(); //file.UserId = group.UserId; if (file.Content == null) { TempData[LeonniConstants.ErrorMessage] = "Please upload Photo"; return(View(objGroup)); // RedirectToAction("Create"); } _repoFile.Add(file); _repoFile.Save(); EntityFileModel efModel = new EntityFileModel(); var entityFile = EntityFileMap.Map(efModel); entityFile.SectionId = _repoSection.GetSingle(x => x.SectionName == "Groups").Id; if (objGroup.Id != 0) { entityFile.EntityId = objGroup.Id; } else { entityFile.EntityId = newGroup.Id; } entityFile.FileId = file.Id; _repoEntityFile.Add(entityFile); _repoEntityFile.Save(); } } else { TempData[LeonniConstants.ErrorMessage] = " Update Unsuccessful"; return(View(objGroup)); } TempData[LeonniConstants.SuccessMessage] = "Group Updated Successfully"; return(RedirectToAction("Groups")); } return(View(objGroup)); //TempData[LeonniConstants.SuccessMessage] = " Update Successful"; //return RedirectToAction("Groups", new { model = objGroup }); } catch (Exception e) { TempData[LeonniConstants.ErrorMessage] = e.ToString(); return(View(objGroup)); } } }
public PartialViewResult FrontList(string name, string countryName, int?provinceId, int?disciplineId, string sex, int?categoryId, int?sortOrder, int?pageNumber = null, int?itemsPerPage = null) { int profileListCount = 0; int groupListCount = 0; int offset = 0; offset = (((int)pageNumber - 1) * (int)itemsPerPage); List <FrontContentModel> lstFrontContent = new List <FrontContentModel>(); FrontContentModel objFrontContent = new FrontContentModel(); objFrontContent.UserProfiles = new List <UserProfileModel>(); objFrontContent.Groups = new List <GroupModel>(); lstFrontContent = FrontContentMap.Map(_repFrontContent.GetList(x => true).ToList()); List <long> lstUserProfileId = new List <long>(); List <long> lstGroupId = new List <long>(); if (lstFrontContent.Count != 0) { ////For listing Front Profiles Contents lstUserProfileId = lstFrontContent.Where(x => x.SectionId == 1).Select(x => x.ContentId).ToList(); foreach (long item in lstUserProfileId) { var objuser = _repUserProfile.GetSingle(x => x.Id == item); if (objuser != null) { UserProfileModel objUserProfile = UserProfileMap.Map(objuser); objFrontContent.UserProfiles.Add(objUserProfile); profileListCount++; var objEntityFile = _repEntityFile.GetSingle(x => x.EntityId == item && x.Section.SectionName == "Users"); if (objEntityFile != null) { objUserProfile.FileId = objEntityFile.FileId; } } } lstGroupId = lstFrontContent.Where(x => x.SectionId == 2).Select(x => x.ContentId).ToList(); groupListCount = lstGroupId.Count; foreach (long item in lstGroupId) { GroupModel objGroups = GroupMap.Map(_repGroup.GetSingle(x => x.Id == item)); if (objGroups != null) { objFrontContent.Groups.Add(objGroups); var objEntityFile = _repEntityFile.GetSingle(x => x.EntityId == item && x.Section.SectionName == "Groups"); if (objEntityFile != null) { objGroups.FileId = objEntityFile.FileId; } } } } ViewBag.PagedListofUserProfiles = objFrontContent.UserProfiles ?? new List <UserProfileModel>(); ViewBag.PagedListofGroups = objFrontContent.Groups ?? new List <GroupModel>(); ViewBag.TotalCount = profileListCount + groupListCount; return(PartialView("_FrontContentList")); }
public ActionResult Profile(UserProfileModel objProfile) { if (objProfile.CategoryId == 0) { TempData[LeonniConstants.ErrorMessage] = " Please Select Any Category"; return(View(objProfile)); } if (objProfile.DisciplineId == 0) { TempData[LeonniConstants.ErrorMessage] = " Please Select Any Discipline"; return(View(objProfile)); } else if (objProfile.Sex == "Sex") { TempData[LeonniConstants.ErrorMessage] = " Please Select Any Sex"; return(View(objProfile)); } else if (objProfile.CountryName == "Country") { TempData[LeonniConstants.ErrorMessage] = " Please Select Any Country"; return(View(objProfile)); } if (objProfile.StateId == 0) { TempData[LeonniConstants.ErrorMessage] = " Please Select Any State"; return(View(objProfile)); } else { try { ViewBag.DisciplineId = new SelectList(_repoDiscipline.GetList().ToList(), "Id", "DisciplineName", ""); if (ModelState.IsValid) { if (objProfile.IsNew == true) { objProfile.IsLeonniTeam = false; objProfile.UserId = CurrentUser.UserId; objProfile.CreatedDate = DateTime.Now; objProfile.StatusId = (int)Status.Active; ////Active _repoUserProfile.Add(UserProfileMap.Map(objProfile)); _repoUserProfile.Save(); objProfile.Id = _repoUserProfile.GetList(x => true).Select(x => x.Id).Max(); } else { if (objProfile.FileId != null)//if (objProfile.ProfilePic != null) { var entityFileModel = _repoEntityFile.GetSingle(x => x.SectionId == 1 && x.EntityId == objProfile.Id); if (entityFileModel != null) { var fileModel = _repoFile.GetSingle(x => x.Id == entityFileModel.FileId); if (fileModel != null) { _repoFile.Delete(fileModel); _repoFile.Save(); } if (entityFileModel != null) { _repoEntityFile.Delete(entityFileModel); _repoEntityFile.Save(); } } } objProfile.UserId = CurrentUser.UserId; objProfile.ModifiedDate = DateTime.Now; _repoUserProfile.Update(UserProfileMap.Map(objProfile)); _repoUserProfile.Save(); } if (objProfile.FileId != null) //if (objProfile.ProfilePic != null && objProfile.ProfilePic.InputStream != null) { ////////Delete the existing entity and file ////EntityFileModel objEntityFile = EntityFileMap.Map(_repoEntityFile.GetSingle(x => x.SectionId == 1 && x.EntityId == objProfile.Id)); ////Leonni.Models.File objFile = _repoFile.GetSingle(x => x.Id == objEntityFile.FileId); ////_repoFile.Delete(objFile); ////_repoFile.Save(); ////var obj1 = EntityFileMap.Map(objEntityFile); ////_repoEntityFile.Delete(EntityFileMap.Map(objEntityFile)); ////_repoEntityFile.Save(); /////Delete the existing file ///// //var file = new Models.File(); //file.ContentType = objProfile.ProfilePic.ContentType; //file.FileName = objProfile.ProfilePic.FileName; //var memoryStream = new MemoryStream(); //objProfile.ProfilePic.InputStream.CopyTo(memoryStream); //Image obj = Image.FromStream(objProfile.ProfilePic.InputStream, true, true); //file.Content = memoryStream.ToArray(); //file.Height = obj.Height; //file.Width = obj.Width; //if (file.Content == null) //{ // TempData[LeonniConstants.ErrorMessage] = "Please upload Photo"; // return View(objProfile); // RedirectToAction("Create"); //} //_repoFile.Add(file); //_repoFile.Save(); //EntityFileModel objEntityFile = new EntityFileModel(); //objEntityFile.SectionId = _repoSection.GetSingle(x => x.SectionName == "Users").Id; //objEntityFile.EntityId = objProfile.Id; //objEntityFile.FileId = file.Id; //_repoEntityFile.Add(EntityFileMap.Map(objEntityFile)); //_repoEntityFile.Save(); EntityFileModel efModel = new EntityFileModel(); var entityFile = EntityFileMap.Map(efModel); entityFile.SectionId = _repoSection.GetSingle(x => x.SectionName == "Users").Id; entityFile.EntityId = objProfile.Id; entityFile.FileId = objProfile.FileId; _repoEntityFile.Add(entityFile); _repoEntityFile.Save(); } } else { TempData[LeonniConstants.ErrorMessage] = " Update Unsuccessful"; return(View(objProfile)); } TempData[LeonniConstants.SuccessMessage] = "Profile Updated Successfully"; return(RedirectToAction("Profile")); } catch (Exception e) { TempData[LeonniConstants.ErrorMessage] = e.ToString(); return(View(objProfile)); } } }