Example #1
0
        public List <CustomerType> GetCustomerTypes()
        {
            List <CustomerType> customerTypes = new List <CustomerType>();

            try
            {
                customerTypes = _dbManager.GetCustomerTypes();
            }
            catch (Exception ex)
            {
                ExceptionPolicy.HandleException(ex, "Policy");
                FaultDetail faultDetail = new FaultDetail
                {
                    Type      = ex.Message,
                    ErrorCode = 63873928
                };     //+ throw
                throw new FaultException <FaultDetail>(faultDetail, ex.Message);
            }
            return(customerTypes);
        }
Example #2
0
        public List <CreditControlStatus> GetCreditControlStatus()
        {
            List <CreditControlStatus> creditControlStatuses = new List <CreditControlStatus>();

            try
            {
                creditControlStatuses = _dbManager.GetCreditControlStatus();
            }
            catch (Exception ex)
            {
                ExceptionPolicy.HandleException(ex, "Policy");
                FaultDetail faultDetail = new FaultDetail
                {
                    Type      = ex.Message,
                    ErrorCode = 63873928
                };     //+ throw
                throw new FaultException <FaultDetail>(faultDetail, ex.Message);
            }
            return(creditControlStatuses);
        }
Example #3
0
        public List <BillingUnit> GetBillingUnits()
        {
            List <BillingUnit> billingUnits = new List <BillingUnit>();

            try
            {
                billingUnits = _dbManager.GetBillingUnits();
            }
            catch (Exception ex)
            {
                ExceptionPolicy.HandleException(ex, "Policy");
                FaultDetail faultDetail = new FaultDetail
                {
                    Type      = ex.Message,
                    ErrorCode = 63873928
                };     //+ throw
                throw new FaultException <FaultDetail>(faultDetail, ex.Message);
            }
            return(billingUnits);
        }
Example #4
0
        public List <Contact> GetContacts(int seqPartyId)
        {
            List <Contact> contacts = new List <Contact>();

            try
            {
                contacts = _dbManager.GetContacts(seqPartyId);
            }
            catch (Exception exceptionToHandle)
            {
                ExceptionPolicy.HandleException(exceptionToHandle, "Policy");
                FaultDetail faultDetail = new FaultDetail
                {
                    Type      = exceptionToHandle.Message,
                    ErrorCode = 63873928
                };     //+ throw
                throw new FaultException <FaultDetail>(faultDetail, exceptionToHandle.Message);
            }

            return(contacts);
        }
Example #5
0
        public List <Customer> SearchCustomers(CustomerSearchCriteria criteria)
        {
            List <Customer> customers = new List <Customer>();

            try
            {
                customers = _dbManager.SearchCustomers(criteria);
            }
            catch (Exception exceptionToHandle)
            {
                ExceptionPolicy.HandleException(exceptionToHandle, "Policy");
                FaultDetail faultDetail = new FaultDetail
                {
                    Type      = exceptionToHandle.Message,
                    ErrorCode = 63873928
                };     //+ throw
                throw new FaultException <FaultDetail>(faultDetail, exceptionToHandle.Message);
            }

            return(customers);
        }
Example #6
0
        public List <Priority> GetPriorities()
        {
            List <Priority> priorities = new List <Priority>();

            try
            {
                priorities = _dbManager.GetPriorities();
            }
            catch (Exception exceptionToHandle)
            {
                ExceptionPolicy.HandleException(exceptionToHandle, "Policy");
                FaultDetail faultDetail = new FaultDetail
                {
                    Type      = exceptionToHandle.Message,
                    ErrorCode = 63873928
                };     //+ throw
                throw new FaultException <FaultDetail>(faultDetail, exceptionToHandle.Message);
            }

            return(priorities);
        }
Example #7
0
        public CustomerSummary GetCustomerSummaryDetails(int seqPartyId)
        {
            CustomerSummary custSumm = new CustomerSummary();

            try
            {
                custSumm = _dbManager.GetCustomerSummaryDetails(seqPartyId);
            }
            catch (Exception exceptionToHandle)
            {
                ExceptionPolicy.HandleException(exceptionToHandle, "Policy");
                FaultDetail faultDetail = new FaultDetail
                {
                    Type      = exceptionToHandle.Message,
                    ErrorCode = 63873928
                };     //+ throw
                throw new FaultException <FaultDetail>(faultDetail, exceptionToHandle.Message);
            }

            return(custSumm);
        }
Example #8
0
        public CustomerDetails GetCustomerDetails(int customerNo)
        {
            CustomerDetails custDetails = new CustomerDetails();

            try
            {
                custDetails = _dbManager.GetCustomerDetails(customerNo);
            }
            catch (Exception exceptionToHandle)
            {
                ExceptionPolicy.HandleException(exceptionToHandle, "Policy");
                FaultDetail faultDetail = new FaultDetail
                {
                    Type      = exceptionToHandle.Message,
                    ErrorCode = 63873928
                };     //+ throw
                throw new FaultException <FaultDetail>(faultDetail, exceptionToHandle.Message);
            }

            return(custDetails);
        }
Example #9
0
    public static void Ctor_TDetail_FaultReason()
    {
        var detail    = new FaultDetail("Fault Message");
        var reason    = new FaultReason("Fault reason");
        var exception = new FaultException <FaultDetail>(detail, reason);

        Assert.NotNull(exception);
        Assert.NotNull(exception.Detail);
        Assert.NotNull(exception.Reason);
        Assert.NotNull(exception.Code);
        Assert.Equal(detail, exception.Detail);
        Assert.Equal(reason, exception.Reason);

        FaultDetail nullDetail = null;
        FaultReason nullReason = null;
        var         exception2 = new FaultException <FaultDetail>(nullDetail, nullReason);

        Assert.NotNull(exception2);
        Assert.NotNull(exception2.Code);
        Assert.NotNull(exception2.Reason);
        Assert.Null(exception2.Detail);
    }
Example #10
0
        /// <summary>
        /// Register new user with unique login name and password.
        /// </summary>
        /// <param name="login">User login name.</param>
        /// <param name="password">User password.</param>
        /// <returns>Created user object.</returns>
        public UserDTO Register(string login, string password)
        {
            if (string.IsNullOrWhiteSpace(login))
            {
                throw new ArgumentException("Username must not be empty.");
            }

            if (string.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentException("Password must not be empty.");
            }

            // Remove leading and closing spaces (user typo)
            string newLogin = login.Trim();

            // Check login min length
            if (newLogin.Length < 5)
            {
                throw new Exception("Username is too short. Minimum length is 5.");
            }

            // Check login max length
            if (newLogin.Length > 50)
            {
                throw new Exception("Username is too long. Maximum length is 50.");
            }

            // Check password min length
            if (password.Length < 5)
            {
                throw new Exception("New password is too short. Minimum length is 5.");
            }

            // Check password max length
            if (password.Length > 255)
            {
                throw new Exception("New password is too long. Maximum length is 255.");
            }

            if (Properties.Settings.Default.Registration_Disabled)
            {
                var log = LogManager.GetCurrentClassLogger();
                log.Warn("Registration failed. Attempt to use username: "******"ERR-REGS-0",
                    ErrorMessage = "Registration failed.",
                    Description  = "Sorry, the subscription is temporarily suspended."
                };

                throw new FaultException <FaultDetail>(
                          faultDetail,
                          new FaultReason(faultDetail.Description),
                          new FaultCode("Receiver"));
            }

            var masterConnection = dbManager.GetMasterConnection(DefaultFolder);

            using (var mc = new MasterEntities(masterConnection))
            {
                var usersMapper = ObjectMapperManager.DefaultInstance.GetMapper <User, UserDTO>();

                // Check login uniqueness
                if (!ModelHelper.IsLoginAvailable(mc, newLogin))
                {
                    var faultDetail = new FaultDetail
                    {
                        ErrorCode    = "ERR-REGS-1",
                        ErrorMessage = "Registration failed.",
                        Description  = string.Format("Sorry, but username \"{0}\" is already in use. Please, try to pick another username.", newLogin)
                    };

                    throw new FaultException <FaultDetail>(
                              faultDetail,
                              new FaultReason(faultDetail.Description),
                              new FaultCode("Receiver"));
                }

                var user = new User
                {
                    Id         = Guid.NewGuid(),
                    Login      = newLogin,
                    Password   = password.Hash(),
                    Registered = DateTime.UtcNow,
                    IsDisabled = false,
                    ServiceUrl = string.Empty                           // default service for all users (for now)
                };

                // Create personal database for user and save path to it
                // TODO: use custom password here to encrypt database with
                user.DatabasePath = dbManager.CreatePersonalDatabase(user.Id, user.Registered, DefaultFolder /*, password*/);

                mc.Users.AddObject(user);
                mc.SaveChanges();

                // Creating default $ account
                var moneyService = new MoneyService {
                    UserName = user.Login
                };
                moneyService.CreateAccount("Cash", 2);

                return(usersMapper.Map(user));
            }
        }
Example #11
0
        /// <summary>
        /// Sets the detail of information being returned in the fault collection object during an unhandled service
        /// exception.
        /// </summary>
        /// <param name="detail">The detail of fault information.</param>
        /// <returns>The configuration options object.</returns>
        public RestOptions WithFaultDetail(FaultDetail detail)
        {
            if (!Enum.IsDefined(typeof(FaultDetail), detail))
            {
                throw new ArgumentOutOfRangeException("detail");
            }

            FaultDetail = detail;
            return this;
        }