/// <summary>
        /// <see cref="Microsoft.Samples.NLayerApp.DistributedServices.MainModule.IMainModuleService"/>
        /// </summary>
        /// <param name="customer"><see cref="Microsoft.Samples.NLayerApp.DistributedServices.MainModule.IMainModuleService"/></param>
        public void RemoveCustomer(Customer customer)
        {
            try
            {
                using (ICustomerManagementService customerService = IoCFactory.Instance.CurrentContainer.Resolve <ICustomerManagementService>())
                {
                    customerService.RemoveCustomer(customer);
                }
            }
            catch (ArgumentNullException ex)
            {
                //trace data for internal health system and return specific FaultException here!
                //Log and throw is a knowed anti-pattern but in this point ( entry point for clients this is admited!)

                //log exception for manage health system
                ITraceManager traceManager = IoCFactory.Instance.CurrentContainer.Resolve <ITraceManager>();
                traceManager.TraceError(ex.Message);

                //propagate exception to client
                ServiceError detailedError = new ServiceError()
                {
                    ErrorMessage = Resources.Messages.exception_InvalidArguments
                };

                throw new FaultException <ServiceError>(detailedError);
            }
        }
        public ActionResult Register(string firstname, string lastname, string email,
                                     string month, string year, string day, string password)
        {
            var dateofbirth = new DateTime();
            var dob         = month + "/" + day + "/" + year;

            DateTime.TryParse(dob, out dateofbirth);
            var customer = new Customer
            {
                FirstName = firstname,
                LastName  = lastname,
                Email     = email,
                Password  = password,
                DOB       = dateofbirth,
            };

            try
            {
                _customerManagementService.Enroll(customer);
                customer = _customerManagementService.GetCustomerByEmail(email);
                _addressManagementService.AddNewAddress(new CustomerAddress {
                    CustomerID = customer.Id
                });
                return(RedirectToAction("Home", "ContestIndex"));
            }
            catch (Exception)
            {
                if (customer != null)
                {
                    _customerManagementService.RemoveCustomer(customer.Id.ToString());
                }
                return(RedirectToAction("Index"));
            }
        }
        public ActionResult Register(string FirstName, string LastName, string Email, string Phone,
                                     string Street, string City, string State, string Password, string PostalCode)
        {
            var customer = new Customer
            {
                FirstName   = FirstName,
                LastName    = LastName,
                Email       = Email,
                PhoneNumber = Phone,
                Password    = Password
            };

            try
            {
                _customerManagementService.Enroll(customer);
                customer = _customerManagementService.GetCustomerByEmail(Email);
                _addressManagementService.AddNewAddress(new CustomerAddress {
                    Street = Street, City = City, State = State, CustomerID = customer.CustomerID, ZipCode = PostalCode
                });
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                if (customer != null)
                {
                    _customerManagementService.RemoveCustomer(customer.Id.ToString());
                }
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
        }
        public void DeleteCustomer_Invoke_NullCustomerThrowArgumentNullException_Test()
        {
            //Arrange
            ICustomerManagementService customerService = IoCFactory.Instance.CurrentContainer.Resolve <ICustomerManagementService>();

            Customer randomCustomer = null;

            //Act
            customerService.RemoveCustomer(randomCustomer);
        }
Exemplo n.º 5
0
        public ActionResult Delete(string customerCode)
        {
            Customer customer = _CustomerService.FindCustomerByCode(customerCode);

            _CustomerService.RemoveCustomer(customer);
            return(RedirectToAction("Index", new RouteValueDictionary()
            {
                { "page", 0 }, { "pageSize", 10 }
            }));
        }
        public async Task <ActionResult> Register(string firstname, string lastname, string email, string phone,
                                                  string gender, string dob, string accounttype, string password, string agreeToTos)
        {
            var dateofbirth = new DateTime();

            DateTime.TryParse(dob, out dateofbirth);
            var customer = new Customer
            {
                FirstName   = firstname,
                LastName    = lastname,
                Email       = email,
                PhoneNumber = phone,
                Password    = password,
                Gender      = gender,
                DOB         = dateofbirth,
                AccountType = accounttype,
                CreatedDate = DateTime.Now
            };

            try
            {
                if (String.IsNullOrEmpty(password) || String.IsNullOrEmpty(email) || String.IsNullOrEmpty(dob) ||
                    String.IsNullOrEmpty(firstname) || String.IsNullOrEmpty(agreeToTos))
                {
                    throw new Exception(ControllerConstants.missingRequiredFields);
                }
                bool emailIsInUse = await CheckIfEmailExists(email);

                if (emailIsInUse)
                {
                    throw new Exception(ControllerConstants.emailInUse);
                }
                _customerManagementService.Enroll(customer);
                customer = _customerManagementService.GetCustomerByEmail(email);
                _addressManagementService.AddNewAddress(new CustomerAddress {
                    CustomerID = customer.Id
                });
                MailAPI.SendWelcomeMessage(email, firstname);
                return(RedirectToAction("Index", "LogIn"));
            }
            catch (Exception ex)
            {
                if (customer != null)
                {
                    _customerManagementService.RemoveCustomer(customer.Id.ToString());
                }
                TempData["SignUpError"] = ex.Message;
                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 7
0
        public ActionResult Register(WantedUser wantedUser, HttpPostedFileBase video)
        {
            Customer customer = null;

            try
            {
                bool emailIsInUse = _customerManagementService.CheckCustomerExist(wantedUser.Email);
                if (emailIsInUse)
                {
                    throw new Exception(ControllerConstants.emailInUse);
                }
                // Create New User
                customer = new Customer
                {
                    Email       = wantedUser.Email,
                    CreatedDate = DateTime.Now,
                    FirstName   = wantedUser.FirstName,
                    LastName    = wantedUser.LastName,
                    Gender      = wantedUser.Gender,
                    DOB         = wantedUser.DOB
                };
                _customerManagementService.Enroll(customer);
                customer = _customerManagementService.GetCustomerByEmail(wantedUser.Email);
                _addressManagementService.AddNewAddress(new CustomerAddress {
                    CustomerID = customer.Id
                });

                // Persist Wanted Data
                wantedUser.CustomerId            = customer.Id;
                wantedUser.EntryVideoFileName    = video.FileName;
                wantedUser.EntryVideoContentType = video.ContentType;

                using (var reader = new BinaryReader(video.InputStream))
                {
                    wantedUser.EntryVideo = reader.ReadBytes(video.ContentLength);
                }
                _wantedUserManagementService.Create(wantedUser);

                return(RedirectToAction("Subscribe", new { customerId = customer.Id.ToString() }));
            }
            catch (Exception ex)
            {
                if (customer != null)
                {
                    _customerManagementService.RemoveCustomer(customer.Id.ToString());
                }
                TempData["SignUpError"] = ex.Message;
                return(RedirectToAction("Register"));
            }
        }
        public void DeleteCustomer_Invoke_Test()
        {
            //Arrange
            ICustomerManagementService customerService = IoCFactory.Instance.CurrentContainer.Resolve <ICustomerManagementService>();

            Customer randomCustomer = null;

            //Act
            randomCustomer = customerService.FindCustomerByCode("A0001");

            customerService.RemoveCustomer(randomCustomer);

            //Assert

            Customer removedCustomer = customerService.FindCustomerByCode("A0001");

            Assert.IsNull(removedCustomer);
        }