Beispiel #1
0
        public UserOutputDTO GetUserById(int Id)
        {
            User          user    = this.userService.GetUserById(Id);
            UserOutputDTO userOUT = new UserOutputDTO()
            {
                Id    = user.Id,
                Name  = user.Name,
                Email = user.Email
            };

            return(userOUT);
        }
Beispiel #2
0
        public UserOutputDTO Authentication(LoginAuthenticationDTO login)
        {
            User user = this.userService.Authenticate(login.Email, login.Password);

            if (user != null)
            {
                UserOutputDTO userOutput = new UserOutputDTO()
                {
                    Name  = user.Name,
                    Email = user.Email,
                    Id    = user.Id
                };
                return(userOutput);
            }
            return(null);
        }
        public static string GetUsersWithProducts(ProductShopContext context)
        {
            StringBuilder result = new StringBuilder();

            var users = context
                        .Users
                        .Where(us => us.ProductsSold.Any())
                        .Select(us => new UserSoldProductsDTO()
            {
                FirstName    = us.FirstName,
                LastName     = us.LastName,
                Age          = us.Age,
                SoldProducts = new SoldProductsDTO()
                {
                    Count    = us.ProductsSold.Count(),
                    Products = us.ProductsSold.Select(p => new SoldProductDTO()
                    {
                        Name  = p.Name,
                        Price = p.Price
                    })
                               .OrderByDescending(p => p.Price)
                               .ToArray()
                }
            })
                        .OrderByDescending(us => us.SoldProducts.Count)
                        .Take(10)
                        .ToArray();

            var usersOutput = new UserOutputDTO()
            {
                UsersCount = users.Length,
                Users      = users
            };

            var xmlSerializer = new XmlSerializer(typeof(UserOutputDTO), new XmlRootAttribute("Users"));

            var namespaces = new XmlSerializerNamespaces();

            namespaces.Add(String.Empty, String.Empty);

            using (var usersWriter = new StringWriter(result))
            {
                xmlSerializer.Serialize(usersWriter, usersOutput, namespaces);
            }

            return(result.ToString().TrimEnd());
        }
Beispiel #4
0
        public IList <UserOutputDTO> GetUsers()
        {
            IList <UserOutputDTO> usersOut = new List <UserOutputDTO>();

            IList <User> users = this.userService.GetUsers();

            foreach (var u in users)
            {
                UserOutputDTO user = new UserOutputDTO()
                {
                    Id    = u.Id,
                    Name  = u.Name,
                    Email = u.Email
                };
                usersOut.Add(user);
            }

            return(usersOut);
        }