public void CreateFieldsForClaimFromTemplate(Claim claim) { var mytemplate = new ClaimTemplate(); if (claim.ClaimTemplateID != null) { mytemplate = _claimTemplateFactory.GetClaimTemplate(claim.ClaimTemplateID.Value); } foreach (var claimFieldGroupTemplate in mytemplate.ClaimFieldGroupTemplates) { var claimFieldGroup = new ClaimFieldGroup { Name = claimFieldGroupTemplate.Name, Description = claimFieldGroupTemplate.Description, ItemOrder = claimFieldGroupTemplate.ItemOrder }; foreach (var claimFieldTemplate in claimFieldGroupTemplate.ClaimFieldTemplates) { var claimField = new ClaimField { Name = claimFieldTemplate.Name, Code = claimFieldTemplate.Code, ClaimFieldTemplateID = claimFieldTemplate.ClaimFieldTemplateID, ClaimFieldGroupID = claimFieldGroupTemplate.ClaimFieldGroupTemplateID, TemplateBName = claimFieldTemplate.FieldType.TemplateName }; claimFieldGroup.ClaimFields.Add(claimField); } claim.ClaimFieldGroups.Add(claimFieldGroup); } _db.SaveChanges(); _db.Dispose(); }
public int CreateFromTemplate(int claimTemplateId, Dictionary <string, string> formCollection, User currentUser, ClaimTemplate myTemplate) { var claim = new Claim { ClaimTemplateID = claimTemplateId, CreatedBy = "User.Identity.Name", DateCreated = DateTime.Now, UserID = currentUser.UserId, ClaimStatusID = 1, WillisEmployeeID = 1 }; var claimName = claim.CreatedBy + " - " + claim.ClaimTemplateID + " - " + ((claim.DateCreated != null) ? (claim.DateCreated.Value).ToShortDateString() : String.Empty); claim.Name = claimName.Length < 50 ? claimName : claimName.Substring(0, 50); CreateClaim(claim); var claimId = claim.ClaimID; // here yo var fieldTypesList = _db.FieldTypes.ToList(); foreach (var claimFieldGroupTemplate in myTemplate.ClaimFieldGroupTemplates) { var claimFieldGroup = new ClaimFieldGroup { Name = claimFieldGroupTemplate.Name, Description = claimFieldGroupTemplate.Description, ItemOrder = claimFieldGroupTemplate.ItemOrder }; claim.ClaimFieldGroups.Add(claimFieldGroup); foreach (var claimFieldTemplate in claimFieldGroupTemplate.ClaimFieldTemplates) { var claimField = new ClaimField { Name = claimFieldTemplate.Name, Code = claimFieldTemplate.Code, ClaimFieldTemplateID = claimFieldTemplate.ClaimFieldTemplateID, ClaimFieldGroupID = claimFieldGroup.ClaimFieldGroupID, TemplateBName = claimFieldTemplate.FieldType.TemplateName }; claimFieldGroup.ClaimFields.Add(claimField); if (claimField.Code != null && formCollection.Keys.Contains(claimField.Code)) { string value = formCollection[claimField.Code]; if (value != null) { var fieldType = fieldTypesList.Single(ft => ft.FieldTypeID == claimFieldTemplate.FieldTypeID); switch (fieldType.Code) { case "ShortText": claimField.ShortTextValue = value; break; case "LongText": claimField.LongTextValue = value; break; case "Integer": int tmpvalue; claimField.IntegerValue = int.TryParse(value, out tmpvalue) ? tmpvalue : (int?)null; break; case "Float": double tmpvalue2; claimField.FloatValue = double.TryParse(value, out tmpvalue2) ? tmpvalue2 : (double?)null; break; case "Date": DateTime tmpvalue3; claimField.DateValue = DateTime.TryParse(value, out tmpvalue3) ? tmpvalue3 : (DateTime?)null; break; case "DateTime": DateTime tmpvalue4; claimField.DateTimeValue = DateTime.TryParse(value, out tmpvalue4) ? tmpvalue4 : (DateTime?)null; break; case "DropDown": claimField.DropDownValue = value; break; case "MultiChoice": claimField.MultiChoiceValue = value; break; case "File": claimField.FileValue = null; break; case "Money": decimal tmpvalue5; claimField.CurrecncyValue = decimal.TryParse(value, out tmpvalue5) ? tmpvalue5 : (decimal?)null; break; case "Country": claimField.CountryValue = value; break; case "Range": double tmpvalue6; claimField.RangeValue = double.TryParse(value, out tmpvalue6) ? tmpvalue6 : (double?)null; break; } } } } } _db.SaveChanges(); return(claimId); }
public int CreateFromTemplate(int claimTemplateId) { var claimTemplateController = new ClaimTemplateController(); var mytemplate = claimTemplateController.GetClaimTemplate(claimTemplateId); var currentUser = _userFactory.GetCurrentUser(); var claim = new Claim { ClaimTemplateID = claimTemplateId, CreatedBy = User.Identity.Name, DateCreated = DateTime.Now, UserID = currentUser.UserId, ClaimStatusID = 1, WillisEmployeeID = 1 }; _db.Claims.Add(claim); string claimName = claim.CreatedBy + " - " + claim.ClaimTemplateID + " - " + ((claim.DateCreated != null) ? (claim.DateCreated.Value).ToShortDateString() : String.Empty); claim.Name = claimName.Length < 50 ? claimName : claimName.Substring(0, 50); _db.SaveChanges(); var claimId = claim.ClaimID; // here yo foreach (var claimFieldGroupTemplate in mytemplate.ClaimFieldGroupTemplates) { var claimFieldGroup = new ClaimFieldGroup { Name = claimFieldGroupTemplate.Name, Description = claimFieldGroupTemplate.Description, ItemOrder = claimFieldGroupTemplate.ItemOrder }; foreach (var claimFieldTemplate in claimFieldGroupTemplate.ClaimFieldTemplates) { var claimField = new ClaimField { Name = claimFieldTemplate.Name, Code = claimFieldTemplate.Code, ClaimFieldTemplateID = claimFieldTemplate.ClaimFieldTemplateID, ClaimFieldGroupID = claimFieldGroupTemplate.ClaimFieldGroupTemplateID, TemplateBName = claimFieldTemplate.FieldType.TemplateName }; claimFieldGroup.ClaimFields.Add(claimField); } claim.ClaimFieldGroups.Add(claimFieldGroup); } _db.SaveChanges(); _db.Dispose(); return(claimId); }