public async Task CreateAsync(ContactCreateRequest rq)
        {
            ContactModel contact = rq.Contact;

            PropertyInfo[]       props      = contact.GetType().GetProperties();
            IEnumerable <string> propValues = props.Select(p => p.GetValue(obj: contact).ToString());
            await FileHandler.AddLineAsync(value : string.Join(separator: ",", propValues.ToArray()));
        }
Exemple #2
0
        public async Task CreateAsync(ContactCreateRequest rq)
        {
            ContactModel dto = rq.Contact;

            if (IsEmailInUse(dto.Email))
            {
                throw new Exception("Email is in use.");
            }

            Contact result = _mapper.Map <Contact>(dto);
            await _db.Contacts.AddAsync(result);

            // Save data
            await _db.SaveChangesAsync();
        }
        public async Task CreateAsync(ContactCreateRequest rq)
        {
            List <ContactModel> allContacts = await ParseContactDataAsync(FilePath);

            if (IsEmailInUse(allContacts, rq.Contact.Email))
            {
                throw new Exception("Email is in use.");
            }

            rq.Contact.Id             = MaxId(allContacts) + 1;
            using StreamWriter writer = new StreamWriter(path: FilePath, append: true);

            using CsvWriter csv = new CsvWriter(writer);

            csv.WriteRecord(rq.Contact);
            await csv.NextRecordAsync();
        }
Exemple #4
0
 public Task CreateAsync(ContactCreateRequest rq)
 {
     return Task.Run(() => _contacts.Add(rq.Contact));
 }