public CustomerDTO Register(CustomerDTO customer) { if (!IsLoginExists(customer.Login)) { _logger.Error($"Customer's unsuccessful registration attempt due to not unique login: {customer}"); return(null); } var result = DBProviderUtil.FunctionWithProvider(p => { var newCustomer = CreateNewCustomerFromDTO(customer); p.Add(newCustomer); return(CustomerToDTO(newCustomer)); }); if (result == null) { _logger.Error($"Customer's unsuccessful registration attempt: {customer}"); } else { _logger.Debug($"Customer's successful registration attempt: {customer}"); } return(result); }
public Customer AddCustomer() { var customer = GenerateCustomer(); DBProviderUtil.ActionWithProvider(provider => provider.Add(customer)); return(customer); }
public NoteDTO UpdateNote(NoteDTO note) { var result = DBProviderUtil.FunctionWithProvider(p => { var updateableNote = p.Select <Note>(n => n.Guid == note.Guid); if (updateableNote == null) { return(null); } updateableNote.Title = note.Title; updateableNote.Text = note.Text; p.Update(updateableNote); return(NoteToDTO(updateableNote)); }); if (result == null) { _logger.Error($"Customer's unsuccessful note update attempt: {note}"); } else { _logger.Debug($"Customer's successful note update attempt: {note}"); } return(result); }
public NoteDTO AddNote(NoteDTO note, Guid customerGuid) { var result = DBProviderUtil.FunctionWithProvider(p => { var customer = p.Select <Customer>(c => c.Guid == customerGuid); if (customer == null) { return(null); } var isNoteUnique = p.Select <Note>(n => n.Guid == note.Guid) == null; if (!isNoteUnique) { return(null); } var newNote = CreateNewNoteFromDTO(note); customer.AddNote(newNote); p.Update(customer); return(NoteToDTO(newNote)); }); if (result == null) { _logger.Error($"Customer's unsuccessful note addition attempt: customerGuid = {customerGuid}, {note}"); } else { _logger.Debug($"Customer's successful note fetching attempt: customerGuid = {customerGuid}, {note}"); } return(result); }
private static bool IsLoginExists(string login) { var isUnique = DBProviderUtil.FunctionWithProvider(p => p.Select <Customer>(c => c.Login == login) == null ); return(isUnique); }
public Customer GetCustomerById(System.Guid id) { Customer customer = null; DBProviderUtil.ActionWithProvider(provider => customer = provider.Select <Customer>(c => c.Guid.ToString() == id.ToString()) ); return(customer); }
public List <ShortNoteDTO> GetNotes(Guid customerGuid) { var result = DBProviderUtil.FunctionWithProvider(p => p.Select <Customer>(c => c.Guid == customerGuid).Notes.Select(NoteToShortDTO).ToList() ); if (result == null) { _logger.Error($"Customer's unsuccessful notes fetching attempt: customerGuid = {customerGuid}"); } else { _logger.Debug($"Customer's successful notes fetching attempt: customerGuid = {customerGuid}, notes = [ {string.Join(", ", result)} ]"); } return(result); }
public NoteDTO GetNote(Guid guid) { var result = DBProviderUtil.FunctionWithProvider(p => { var note = p.Select <Note>(n => n.Guid == guid); return(note != null ? NoteToDTO(note) : null); }); if (result == null) { _logger.Error($"Unsuccessful note fetching attempt with guid: {guid}"); } else { _logger.Debug($"Successful note fetching attempt with guid: {guid}"); } return(result); }
public CustomerDTO Login(string login, string password) { var result = DBProviderUtil.FunctionWithProvider(p => { var customer = p.Select <Customer>(c => c.Login == login); if (customer == null) { return(null); } return(!customer.CheckPassword(password) ? null : GetLoggedInCustomerDTO(customer)); }); if (result == null) { _logger.Error($"Customer's unsuccessful login attempt: login = {login}, password = {password}"); } else { _logger.Debug($"Customer's successful login attempt: {result}"); } return(result); }
public bool DeleteNote(Guid guid) { var result = DBProviderUtil.FunctionWithProvider(p => { var note = p.Select <Note>(n => n.Guid == guid); if (note == null) { return(false); } p.Delete(note); return(true); }); if (!result) { _logger.Error($"Customer's unsuccessful note delete attempt: note guid = {guid}"); } else { _logger.Debug($"Customer's successful note delete attempt: note guid = {guid}"); } return(result); }
public List <Customer> GetAllCustomers() { return(DBProviderUtil.FunctionWithProvider( provider => provider.SelectAll <Customer>().ToList() )); }
public void DeleteCustomer(Customer customer) { DBProviderUtil.ActionWithProvider(provider => provider.Delete(customer)); }
public void EditCustomer(Customer customer) { DBProviderUtil.ActionWithProvider(provider => provider.Update(customer)); }