public async Task ExtractData(Customer customer) { string filePathCSV = @"./wwwroot/Upload/agent.csv"; Task <string> fileData = ReadFileAsync(filePathCSV); await fileData; string[] contents = fileData.Result.Split('\n'); string[] header = contents[0].Split(','); for (int i = 0; i < header.Length; i++) { header[i] = header[i].Replace("\r", string.Empty).Trim('\"'); } int indexOfName = Array.IndexOf(header, "Name"); int indexOfEmail = Array.IndexOf(header, "Email"); int indexOfPhoneNumber = Array.IndexOf(header, "PhoneNumber"); int indexOfProfileImage = Array.IndexOf(header, "ProfileImg"); int indexOfDepartment = Array.IndexOf(header, "Department"); for (int i = 1; i <= contents.Count() - 1; i++) { string[] info = contents[i].Split(','); Agent agent = new Agent { Name = info[indexOfName].Trim('\"'), Email = info[indexOfEmail].Trim('\"'), Phone_no = info[indexOfPhoneNumber].Trim('\"'), Profile_img_url = info[indexOfProfileImage].Trim('\"'), Department = _context.Department.FirstOrDefault(x => x.DepartmentName == info[indexOfDepartment].Trim('\"')) ?? new Department { DepartmentName = info[indexOfDepartment].Trim('\"'), CreatedOn = DateTime.Now, UpdatedOn = DateTime.Now }, Organization = _context.Customer.FirstOrDefault(x => x.Customer_name == customer.Customer_name) ?? customer, CreatedOn = DateTime.Now, UpdatedOn = DateTime.Now }; _context.Agent.Add(agent); await _context.SaveChangesAsync(); } }
public async Task ExtractData(Organisation Organisation) { string filePathCSV = @"./wwwroot/Upload/EndUser.csv"; Task <string> fileData = ReadFileAsync(filePathCSV); await fileData; string[] contents = fileData.Result.Split('\n'); long countOfSocialIds = System.Text.RegularExpressions.Regex.Matches(contents[0], "/Source").Count; string[] header = contents[0].Split(','); for (long i = 0; i < header.Length; i++) { header[i] = header[i].Replace("\r", string.Empty).Trim('\"'); } long indexOfName = Array.IndexOf(header, "Name"); long indexOfEmail = Array.IndexOf(header, "Email"); long indexOfPhoneNumber = Array.IndexOf(header, "PhoneNumber"); long indexOfProfileImage = Array.IndexOf(header, "ProfileImgUrl"); long[] indexOfSocialAccountSource = new long[countOfSocialIds]; long[] indexOfSocialAccountIdentifier = new long[countOfSocialIds]; for (long i = 0; i < countOfSocialIds; i++) { indexOfSocialAccountSource[i] = Array.IndexOf(header, $"SocialId/{i}/Source"); indexOfSocialAccountIdentifier[i] = Array.IndexOf(header, $"SocialId/{i}/Identifier"); } for (long i = 1; i <= contents.Count() - 1; i++) { string[] info = contents[i].Split(','); EndUser endUser = new EndUser { Name = info[indexOfName].Trim('\"'), Email = info[indexOfEmail].Trim('\"'), PhoneNumber = info[indexOfPhoneNumber].Trim('\"'), ProfileImgUrl = info[indexOfProfileImage].Trim('\"'), SocialId = new List <UserSocialId>(), Organization = _context.Organisation.FirstOrDefault(x => x.OrganisationName == Organisation.OrganisationName) ?? Organisation, CreatedOn = DateTime.Now, UpdatedOn = DateTime.Now }; for (long j = 0; j < countOfSocialIds; j++) { if (info[indexOfSocialAccountSource[j]].Trim('\"') != string.Empty && info[indexOfSocialAccountIdentifier[j]].Trim('\"') != string.Empty) { endUser.SocialId.Add(new UserSocialId { Source = info[indexOfSocialAccountSource[j]].Trim('\"'), Identifier = info[indexOfSocialAccountIdentifier[j]].Trim('\"'), CreatedOn = DateTime.Now, UpdatedOn = DateTime.Now }); } } _context.EndUser.Add(endUser); await _context.SaveChangesAsync(); } }
public async Task CreateCredentials(Organisation organisation) { _context.Organisation.Add(organisation); await _context.SaveChangesAsync(); }
public async Task CreateCredentials(Customer customer_Signup) { _context.Customer.Add(customer_Signup); await _context.SaveChangesAsync(); }