public async Task <SaveResult> GenerateRegistrationNotificationEmail( MemberStagingViewModel model, string messageTemplateDiscr) { SaveResult saveResult = new SaveResult(); var mailTemplate = await _messageTemplateBL.GetEntityByName(messageTemplateDiscr); string messageBody = model.IsFinalised ? model.Comments : string.Empty; List <QueuedEmail> msqList = new List <QueuedEmail>(); if (model.NotificationRoles != null && MessageTemplateConst.RegistrationNotification.Equals(messageTemplateDiscr)) { foreach (var recipient in model.NotificationRoles) { BuildEmailQueue(mailTemplate, messageBody, msqList, recipient.Email, recipient.FullName, model.RequestUrl, model.SessionUserId); } } else { BuildEmailQueue(mailTemplate, model.Comments, msqList, model.Email, model.FullName, model.RequestUrl, model.SessionUserId); } if (msqList.Any()) { try { _context.QueuedEmail.AddRange(msqList); _context.SaveChanges(); saveResult.IsSuccess = true; } catch (DbUpdateException ex) { throw ex; } catch (Exception ex) { throw ex; } } else { saveResult.IsSuccess = true; } return(saveResult); }
/// <summary> /// Convert Corporate Object into Corporate Entity /// </summary> ///<param name="model">Corporate</param> ///<param name="CorporateEntity">DataAccess.Corporate</param> ///<returns>DataAccess.Corporate</returns> public static MemberStaging ToEntity(this MemberStagingViewModel model, MemberStaging entity ) { if (entity.Id == 0) { entity.CreatedUserId = model.SessionUserId; } else { entity.UpdatedUserId = model.SessionUserId; entity.UpdatedTimestamp = DateTime.Now; } entity.FirstName = model.FirstName; entity.Surname = model.Surname; entity.ContactNo = model.CellPhone; entity.Email = model.Email; entity.Initials = model.Initials; entity.OtherName = model.OtherName; entity.TitleId = model.TitleId; entity.BirthDate = model.BirthDate; entity.GenderId = model.GenderId; if (model.IDTypeId == 1) { entity.IDNumber = model.IDNumber; } else { entity.IDNumber = model.AlternateIDNumber; } entity.IDTypeId = model.IDTypeId; entity.CountryId = model.NationalityId; entity.AddressId = model.AddressId; entity.IsFromFront = model.IsFromFront; entity.IsFinalised = model.IsFinalised; entity.Occupation = model.Occupation; entity.Company = model.Company; entity.WorkTelephone = model.WorkTelephone; entity.HomeTelephone = model.HomeTelephone; entity.EmmergencyContact1 = model.EmmergencyContact1; entity.EmmergencyContactNo1 = model.EmmergencyContactNo1; entity.EmmergencyContact2 = model.EmmergencyContact2; entity.EmmergencyContactNo2 = model.EmmergencyContactNo2; entity.MedicalAidName = model.MedicalAidName; entity.MedicalAidNumber = model.MedicalAidNumber; entity.PrevYearLicence = model.PrevYearLicence; entity.CurrentYearLicence = model.CurrentYearLicence; return(entity); }
public virtual async Task <JsonResult> SaveModel([FromForm] MemberStagingViewModel viewModel) { SaveResult resultSet = new SaveResult(); if (viewModel.IDTypeId == 1) { ModelState.Remove("AlternateIDNumber"); } else { ModelState.Remove("IDNumber"); } if (ModelState.IsValid) { Type t = viewModel.GetType(); ApplicationUser usr = await GetCurrentUserAsync(); viewModel.SessionUserId = "ca0cdade-73a4-4829-b082-2a3a1a04cce0";// usr.Id; viewModel.NotificationRoles = await GetMessageTemplateNotificationUser(); viewModel.RequestUrl = HtmlEncoder.Default.Encode(string.Format("{0}/Admin/MemberApplication", Request.Host)); resultSet = await _entityBL.SaveEntity(viewModel); } else { foreach (var modelState in ModelState.Values) { foreach (var error in modelState.Errors) { resultSet.Message = error.ErrorMessage; } } } return(Json(resultSet)); }
/// <summary> /// Convert Corporate Entity into Corporate Object /// </summary> ///<param name="model">MemberStagingViewModel</param> ///<param name="CorporateEntity">DataAccess.Corporate</param> ///<returns>MemberStagingViewModel</returns> public static MemberStagingViewModel ToViewModel(this MemberStaging entity, MemberStagingViewModel model) { model.Id = entity.Id; model.NationalityId = entity.CountryId; model.FirstName = entity.FirstName; model.Surname = entity.Surname; model.CellPhone = entity.ContactNo; model.Email = entity.Email; model.Initials = entity.Initials; model.OtherName = entity.OtherName; model.TitleId = entity.TitleId ?? 0; model.GenderId = entity.GenderId; model.IDNumber = entity.IDNumber; model.IDTypeId = entity.IDTypeId; model.AddressId = entity.AddressId; model.AddressId = entity.AddressId; model.BirthDate = entity.BirthDate; model.IsFromFront = entity.IsFromFront; // model.FullName = entity.FullName; model.BirthDateLongDate = entity.BirthDate.ToCustomLongDate(); model.Occupation = entity.Occupation; model.Company = entity.Company; model.WorkTelephone = entity.WorkTelephone; model.HomeTelephone = entity.HomeTelephone; model.EmmergencyContact1 = entity.EmmergencyContact1; model.EmmergencyContactNo1 = entity.EmmergencyContactNo1; model.EmmergencyContact2 = entity.EmmergencyContact2; model.EmmergencyContactNo2 = entity.EmmergencyContactNo2; model.PrevYearLicence = entity.PrevYearLicence; model.CurrentYearLicence = entity.CurrentYearLicence; model.MedicalAidNumber = entity.MedicalAidNumber; model.MedicalAidName = entity.MedicalAidName; return(model); }
public IActionResult Join(MemberStagingViewModel viewModel) { viewModel = new MemberStagingViewModel(); return(View(viewModel)); }
public async Task <IActionResult> Index(int?Id) { MemberStagingViewModel model = await _entityBL.GetEntityById(Id); return(View(model)); }
public async Task <SaveResult> GenerateEntity(MemberStagingViewModel viewModel) { SaveResult saveResult = new SaveResult(); Dictionary <bool, string> dictionary = new Dictionary <bool, string>(); string memberNo = await _controlBL.GetControlByType(ControlEnum.MemberNo.ToString()); string personGuid = Guid.NewGuid().ToString().Substring(0, 8).ToUpper(); viewModel.PersonGuid = personGuid; var entity = new Person { FirstName = viewModel.FirstName, Surname = viewModel.Surname, ContactNo = viewModel.EmmergencyContactNo1, Email = viewModel.Email, Initials = viewModel.Initials, OtherName = viewModel.OtherName, TitleId = viewModel.TitleId, BirthDate = viewModel.BirthDate, GenderId = viewModel.GenderId, IDNumber = viewModel.IDNumber, IDTypeId = viewModel.IDTypeId, CountryId = viewModel.NationalityId, AddressId = viewModel.AddressId, CreatedUserId = viewModel.SessionUserId, PersonGuid = personGuid }; var memberEntity = new Member { MemberNo = memberNo, Occupation = viewModel.Occupation, Company = viewModel.Company, WorkTelephone = viewModel.WorkTelephone, HomeTelephone = viewModel.HomeTelephone, EmmergencyContact1 = viewModel.EmmergencyContact1, EmmergencyContactNo1 = viewModel.EmmergencyContactNo1, EmmergencyContact2 = viewModel.EmmergencyContact2, EmmergencyContactNo2 = viewModel.EmmergencyContactNo2, CreatedUserId = viewModel.SessionUserId }; // entity.Employees.Add(employeeEntity); entity.Members.Add(memberEntity); _context.Person.Add(entity); try { await _context.SaveChangesAsync(); if (entity.Id > 0) { saveResult.IsSuccess = true; saveResult.Id = entity.Id; viewModel.PersonId = entity.Id; } } catch (DbUpdateException upDateEx) { var results = upDateEx.GetSqlerrorNo(); string msg = results == (int)SqlErrNo.FK ? ConstEntity.MissingValueMsg : ConstEntity.UniqueKeyMsg; saveResult = dictionary.GetValidateEntityResults(msg).ToSaveResult(); } catch (Exception ex) { saveResult.Message = CrudError.DeleteErrorMsg; } return(saveResult); }
public SaveResult GenerateRegistrationEmail( MemberStagingViewModel model, string messageBody) { SaveResult saveResult = new SaveResult(); string recipient = model.Title + " " + model.FirstName + " " + model.Surname; var subscriptionTypes = _context.SubscriptionTypeRuleAudit.Include(a => a.SubscriptionTypeRule.SubscriptionType).ToList(); List <string> messageTemplateList = new List <string>(); messageTemplateList.Add(MessageTemplateConst.AccountConfirmation); messageTemplateList.Add(MessageTemplateConst.AccountSubscription); messageTemplateList.Add(MessageTemplateConst.AccountCredential); var mailTemplates = GetEmailTamplate(messageTemplateList, recipient); List <QueuedEmail> msqList = new List <QueuedEmail>(); foreach (var item in mailTemplates) { if (item != null) { var queueEmail = new QueuedEmail { EmailAccountId = item.EmailAccountId, To = model.Email, Subject = item.Subject, From = item.FromAddress, ToName = recipient, Priority = 5, SentTries = 3, CreatedTimestamp = DateTime.Now, CreatedUserId = model.SessionUserId }; if (item.Name == MessageTemplateConst.AccountCredential) { queueEmail.Body = messageBody; } else if (item.Name == MessageTemplateConst.AccountConfirmation) { queueEmail.Body = GenerateBody(item, recipient, null, null); } else { queueEmail.Body = GenerateSubscriptionBody(subscriptionTypes, item, recipient, model.RequestUrl); } if (item.DelayHours > 0) { queueEmail.DontSendBeforeDate = DateTime.Now.AddHours(item.DelayHours); } msqList.Add(queueEmail); } } if (msqList.Any()) { try { _context.QueuedEmail.AddRange(msqList); _context.SaveChanges(); saveResult.IsSuccess = true; } catch (DbUpdateException ex) { throw ex; } catch (Exception ex) { throw ex; } } else { saveResult.IsSuccess = true; } return(saveResult); }