コード例 #1
0
ファイル: AptekaNetService.cs プロジェクト: Bajena/aptekanet
 public AptekaNetService()
 {
     _userSignedIn = false;
     _signedCustomerId = 0;
     _customerAssembler = new CustomerAssembler();
     _pharmacyAssembler = new PharmacyAssembler();
     _medicineAssembler = new MedicineAssembler();
     _productAssembler = new ProductAssembler();
 }
コード例 #2
0
ファイル: AptekaNetService.cs プロジェクト: Bajena/aptekanet
        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
                    };
            }
        }