Ejemplo n.º 1
0
        public MethodResult <User> GetByEmail(string email)
        {
            var user = _userRepository.GetByEmail(email);

            if (user != null)
            {
                return(new MethodResult <User>(user));
            }
            return(MethodResult <User> .CreateFaultedResult("The user can't be found."));
        }
Ejemplo n.º 2
0
        public MethodResult <TicketItem> GetById(int ticketItemId)
        {
            var ticketItem = _ticketItemRepository.GetById(ticketItemId);

            if (ticketItem != null)
            {
                return(new MethodResult <TicketItem>(ticketItem));
            }

            return(MethodResult <TicketItem> .CreateFaultedResult("The ticketItem with this Id can't be found."));
        }
Ejemplo n.º 3
0
        public MethodResult <Customer> GetByEmailForUser(string email, int userId)
        {
            var customer = _customerRepository.GetByEmailForUser(email, userId);

            if (customer != null)
            {
                return(new MethodResult <Customer>(customer));
            }

            return(MethodResult <Customer> .CreateFaultedResult("The customer with this email can't be found."));
        }
Ejemplo n.º 4
0
        public MethodResult <Customer> GetById(int customerId)
        {
            var customer = _customerRepository.GetById(customerId);

            if (customer != null)
            {
                return(new MethodResult <Customer>(customer));
            }

            return(MethodResult <Customer> .CreateFaultedResult("The customer with this Id can't be found."));
        }
Ejemplo n.º 5
0
        public MethodResult <Ticket> GetById(int ticketId)
        {
            var ticket = _ticketRepository.GetById(ticketId);

            if (ticket != null)
            {
                return(new MethodResult <Ticket>(ticket));
            }

            return(MethodResult <Ticket> .CreateFaultedResult("The ticket with this Id can't be found."));
        }
Ejemplo n.º 6
0
        public MethodResult <Asset> GetBySerialNumberForCustomer(string serialNumber, int customerId)
        {
            var asset = _assetRepository.GetBySerialNumberForCustomer(serialNumber, customerId);

            if (asset != null)
            {
                return(new MethodResult <Asset>(asset));
            }

            return(MethodResult <Asset> .CreateFaultedResult("The asset with this serial number can't be found."));
        }
Ejemplo n.º 7
0
        public MethodResult <Asset> GetById(int assetId)
        {
            var asset = _assetRepository.GetById(assetId);

            if (asset != null)
            {
                return(new MethodResult <Asset>(asset));
            }

            return(MethodResult <Asset> .CreateFaultedResult("The asset with this Id can't be found."));
        }
Ejemplo n.º 8
0
        public MethodResult <User> GetById(int userId)
        {
            var user = _userRepository.GetById(userId);

            if (user != null)
            {
                return(new MethodResult <User>(user));
            }

            return(MethodResult <User> .CreateFaultedResult("The user can't be found."));
        }
Ejemplo n.º 9
0
        public MethodResult <User> FindByEmailAndPassword(string email, string password)
        {
            var users = _userRepository.GetAll();
            var user  = users.FirstOrDefault(x => x.Email == email && x.Password == EncryptPassword(password));

            if (user == null)
            {
                return(MethodResult <User> .CreateFaultedResult("The user does not exist!"));
            }

            return(new MethodResult <User>(user));
        }
Ejemplo n.º 10
0
        public VoidResult DeleteCustomer(int customerId)
        {
            var deleteCustomer = _customerRepository.GetById(customerId);

            if (deleteCustomer != null)
            {
                _customerRepository.Delete(deleteCustomer.Id);
                return(VoidResult.Ok());
            }
            else
            {
                return(MethodResult <Customer> .CreateFaultedResult("The customer with this Id can't be found."));
            }
        }
Ejemplo n.º 11
0
        public MethodResult <Asset> UpdateAsset(int id, string serialNumber, string name, string description)
        {
            var updateAsset = _assetRepository.GetById(id);

            if (updateAsset != null)
            {
                updateAsset.SerialNumber = serialNumber;
                updateAsset.Name         = name;
                updateAsset.Description  = description;

                _assetRepository.Update(updateAsset);

                return(new MethodResult <Asset>(updateAsset));
            }
            else
            {
                return(MethodResult <Asset> .CreateFaultedResult("The asset with this Id can't be found."));
            }
        }
Ejemplo n.º 12
0
        public MethodResult <User> UpdateUser(int userId, string fullName, string address, string phone)
        {
            var updateUser = _userRepository.GetById(userId);

            if (updateUser != null)
            {
                updateUser.FullName = fullName;
                updateUser.Address  = address;
                updateUser.Phone    = phone;

                _userRepository.Update(updateUser);

                return(new MethodResult <User>(updateUser));
            }
            else
            {
                return(MethodResult <User> .CreateFaultedResult("The user can't be found."));
            }
        }
Ejemplo n.º 13
0
        public MethodResult <Customer> UpdateCustomer(int customerId, string name, string address, string city, string phone)
        {
            var updateCustomer = _customerRepository.GetById(customerId);

            if (updateCustomer != null)
            {
                updateCustomer.Name    = name;
                updateCustomer.Address = address;
                updateCustomer.City    = city;
                updateCustomer.Phone   = phone;

                _customerRepository.Update(updateCustomer);

                return(new MethodResult <Customer>(updateCustomer));
            }
            else
            {
                return(MethodResult <Customer> .CreateFaultedResult("The customer with this Id can't be found."));
            }
        }
Ejemplo n.º 14
0
        public MethodResult <Asset> AddAsset(string serialNumber, string name, string description, int customerId)
        {
            var existingAsset = _assetRepository.GetBySerialNumberForCustomer(serialNumber, customerId);

            if (existingAsset != null)
            {
                return(MethodResult <Asset> .CreateFaultedResult("The asset is already created."));
            }

            var newAsset = new Asset
            {
                SerialNumber = serialNumber,
                Name         = name,
                Description  = description,
                CustomerId   = customerId
            };

            _assetRepository.Add(newAsset);

            return(new MethodResult <Asset>(newAsset));
        }
Ejemplo n.º 15
0
        public MethodResult <Customer> AddCustomer(string name, string email, string address, string city, string phone, int userId)
        {
            var existingCustomer = _customerRepository.GetByEmailForUser(email, userId);

            if (existingCustomer != null)
            {
                return(MethodResult <Customer> .CreateFaultedResult("The Email is taken for the user."));
            }

            var newCustomer = new Customer
            {
                Name    = name,
                Email   = email,
                Address = address,
                City    = city,
                Phone   = phone,
                UserId  = userId
            };

            _customerRepository.Add(newCustomer);

            return(new MethodResult <Customer>(newCustomer));
        }
Ejemplo n.º 16
0
        public MethodResult <User> Register(string email, string fullName, string address, string phone, string password, string confirmPassword)
        {
            // Check rules
            var existingUser = _userRepository.GetByEmail(email);

            if (existingUser != null)
            {
                return(MethodResult <User> .CreateFaultedResult("The email is taken."));
            }

            if (password != confirmPassword)
            {
                return(MethodResult <User> .CreateFaultedResult("Password and Confirm Password do not match."));
            }

            if (password.Length >= 1 && password.Length < 6)
            {
                return(MethodResult <User> .CreateFaultedResult("The password is too short."));
            }

            // Create user
            var user = new User
            {
                FullName = fullName,
                Email    = email,
                Address  = address,
                Phone    = phone,
                Password = EncryptPassword(password)
            };

            // Save the user
            _userRepository.Add(user);

            // Return the user
            return(new MethodResult <User>(user));
        }