public List <StageModel> GetStages(int CompanyId) { List <StageModel> stageModelList = new List <StageModel>(); List <Stage> stageList = stageRepository.GetAll(r => r.CompanyId == CompanyId && r.RecordDeleted == false).OrderBy(n => n.StageOrder).ToList(); AutoMapper.Mapper.Map(stageList, stageModelList); return(stageModelList); }
public LeadModel AddLead(LeadModel leadModel) { Lead lead = new Lead(); LeadModel _leadmodel = new LeadModel(); RatingModel ratingModel = new RatingModel(); if (!leadModel.LeadSourceId.HasValue || leadModel.LeadSourceId.Value == 0) { leadModel.LeadSourceId = null; leadModel.LeadSourceModel = null; } if (!leadModel.LeadStatusId.HasValue || leadModel.LeadStatusId.Value == 0) { leadModel.LeadStatusId = null; leadModel.LeadStatusModel = null; } if (!leadModel.IndustryId.HasValue || leadModel.IndustryId.Value == 0) { leadModel.IndustryId = null; leadModel.IndustryModel = null; } AutoMapper.Mapper.Map(leadModel, lead); lead.RatingId = leadModel.RatingId > 0 ? leadModel.RatingId : null; lead.CreatedDate = DateTime.UtcNow; lead.CreatedBy = leadModel.CreatedBy; lead.ModifiedDate = DateTime.UtcNow; // StageModel stageModel = stageBusiness.GetIntialStage((int)leadModel.CompanyId); List <Stage> stageList = new List <Stage>(); stageList = stageRepository.GetAll(r => r.CompanyId == lead.CompanyId && r.RecordDeleted == false).OrderBy(r => r.StageOrder).ToList(); if (lead.AccountId > 0) { if (stageList.Count > 2) { Stage stage = stageList.FirstOrDefault(r => r.StageOrder >= Constants.ACCOUNT_LEAD_STAGE); lead.StageId = stage.StageId; lead.RatingId = stage.Rating.RatingId; } else { lead.StageId = stageList.SingleOrDefault(r => r.IsInitialStage == true).StageId; } } else { lead.StageId = stageList.SingleOrDefault(r => r.IsInitialStage == true).StageId; } lead.Address = ValidateAddress(lead.Address, leadModel.AddressModel); leadRepository.Insert(lead); AddLeadToDateAudit(lead, false); AutoMapper.Mapper.Map(lead, _leadmodel); _leadmodel.Rating = ratingModel; return(_leadmodel); }
public UserModel RegisterUser(UserModel userModel) { User user = new User(); user.Company = new Company(); AutoMapper.Mapper.Map(userModel, user); user.CreatedDate = DateTime.UtcNow; user.Active = true; user.ProfileId = GetDefaultRegistertedUserProfileId();//(int)Enums.Profile.Administrator; user.UserTypeId = (int)Enums.UserType.User; user.RoleId = roleRepository.SingleOrDefault(x => x.IsDefaultForRegisterdUser == true && x.RecordDeleted == false).RoleId; user.Address = null; user.Profile = null; user.Role = null; user.Company.CreatedOn = DateTime.UtcNow; user.Company.IsActive = true; if (user.CultureInformationId == 0) { user.CultureInformationId = null; } if (user.TimezoneId == 0) { user.TimezoneId = null; } userRepository.Insert(user); UserSetting userSetting = new UserSetting(); userSetting.IsSendNotificationsRecentActivities = true; userSetting.UserId = user.UserId; accountRepository.Insert(userSetting); //Add the default stage for newly created company of registered user List <Stage> listDefaultStages = stageRepositry.GetAll(x => x.CompanyId == null).ToList(); for (int i = 0; i < listDefaultStages.Count; i++) { Stage objDefaultStage = new Stage(); objDefaultStage = listDefaultStages[i]; objDefaultStage.CompanyId = user.CompanyId; if (objDefaultStage.IsInitialStage == true) { objDefaultStage.StageOrder = 0; } else if (objDefaultStage.IsLastStage == true) { objDefaultStage.StageOrder = 100; } stageRepositry.Insert(objDefaultStage); } user = userRepository.SingleOrDefault(r => r.UserId == user.UserId); AutoMapper.Mapper.Map(user, userModel); //Code Added by mahesh bhatt for loading a user after register with full permission AutoMapper.Mapper.Map(user.Company, userModel.CompanyModel); AutoMapper.Mapper.Map(user.Profile, userModel.ProfileModel); AutoMapper.Mapper.Map(user.CultureInformation, userModel.CultureInformationModel); List <ProfilePermissionModel> profilePermissionModels = new List <ProfilePermissionModel>(); AutoMapper.Mapper.Map(user.Profile.ProfilePermissions, profilePermissionModels); userModel.ProfileModel.ProfilePermissionModels = profilePermissionModels; ModulePermissionModel modulePermissionModel = new ModulePermissionModel(); AutoMapper.Mapper.Map(user.Profile.ProfilePermissions, profilePermissionModels); userModel.ProfileModel.ProfilePermissionModels = profilePermissionModels; /////////////////////////////////////// profileRepository.CreateDefaultStandardProfile(user.CompanyId); return(userModel); }