Esempio n. 1
0
 public AptekaNetService()
 {
     _userSignedIn = false;
     _signedCustomerId = 0;
     _customerAssembler = new CustomerAssembler();
     _pharmacyAssembler = new PharmacyAssembler();
     _medicineAssembler = new MedicineAssembler();
     _productAssembler = new ProductAssembler();
 }
Esempio n. 2
0
        public RegistrationResponse RegisterNewCustomer(RegistrationRequest request)
        {
            try
            {
                using (var unitOfWork = new AptekaNetUnitOfWork())
                {
                    foreach (var customer in unitOfWork.Context.Customers)
                    {
                        Debug.WriteLine("USER: {0} , {1}", customer.Login, customer.Password);
                    }

                    if (!unitOfWork.CustomerRepository.IsCustomerLoginUnique(request.NewCustomerData.Login))
                        return new RegistrationResponse(request.Id, false)
                            {
                                Message = "Użytkownik o podanym loginie już istnieje"
                            };

                    var customerAssembler = new CustomerAssembler();
                    Customer newCustomerEntity = customerAssembler.ToNewCustomerEntity(request.NewCustomerData);

                    unitOfWork.CustomerRepository.Create(newCustomerEntity);
                    unitOfWork.SaveChanges();

                    return new RegistrationResponse(request.Id, true);
                }
            }
            catch (DbEntityValidationException e)
            {
                var message = e.EntityValidationErrors.Aggregate("Nieprawidłowe dane użytkownika: ", (current1, errors) => errors.ValidationErrors.Aggregate(current1, (current, error) => current + (error.ErrorMessage + " ")));
                return new RegistrationResponse(request.Id, false) { Message = message };
            }
            catch (Exception e)
            {
                return new RegistrationResponse(request.Id, false)
                    {
                        Message = "Błąd - " + e.Message
                    };
            }
        }