Пример #1
0
        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);
        }
Пример #2
0
        public Customer AddCustomer()
        {
            var customer = GenerateCustomer();

            DBProviderUtil.ActionWithProvider(provider => provider.Add(customer));
            return(customer);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        private static bool IsLoginExists(string login)
        {
            var isUnique = DBProviderUtil.FunctionWithProvider(p =>
                                                               p.Select <Customer>(c => c.Login == login) == null
                                                               );

            return(isUnique);
        }
Пример #6
0
        public Customer GetCustomerById(System.Guid id)
        {
            Customer customer = null;

            DBProviderUtil.ActionWithProvider(provider =>
                                              customer = provider.Select <Customer>(c => c.Guid.ToString() == id.ToString())
                                              );
            return(customer);
        }
Пример #7
0
        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);
        }
Пример #8
0
        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);
        }
Пример #9
0
        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);
        }
Пример #10
0
        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);
        }
Пример #11
0
 public List <Customer> GetAllCustomers()
 {
     return(DBProviderUtil.FunctionWithProvider(
                provider => provider.SelectAll <Customer>().ToList()
                ));
 }
Пример #12
0
 public void DeleteCustomer(Customer customer)
 {
     DBProviderUtil.ActionWithProvider(provider => provider.Delete(customer));
 }
Пример #13
0
 public void EditCustomer(Customer customer)
 {
     DBProviderUtil.ActionWithProvider(provider => provider.Update(customer));
 }