예제 #1
0
        /// <summary>
        /// Funcion que realiza la Sincronización entre el api externo y la base de datos
        /// </summary>
        /// <returns>true or false</returns>
        public async Task <bool> AuthorSync()
        {
            var authors = await FakeRestAPI.GetAuthors();

            var books = await FakeRestAPI.GetBooks();

            var bookService = new BookService(_unitOfWork);

            foreach (var author in authors)
            {
                var newAuthor = await AuthorGetById(author.id);

                bool bandera = false;
                if (newAuthor == null)
                {
                    newAuthor = new Author()
                    {
                        Id        = author.id,
                        FirstName = author.firstName,
                        LastName  = author.lastName
                    };
                    await Task.FromResult(_unitOfWork.Authors.Insert(newAuthor));

                    bandera = true;
                }
                var newBook = await bookService.BookGetById(author.idBook);

                if (newBook == null)
                {
                    var book = books.Where(x => x.id == author.idBook).FirstOrDefault();
                    if (book != null)
                    {
                        newBook = new Book()
                        {
                            Id          = book.id,
                            Description = book.description,
                            Excerpt     = book.excerpt,
                            Title       = book.title,
                            PageCount   = book.pageCount,
                            PublishDate = book.publishDate
                        };
                        await bookService.BookCreate(newBook);

                        bandera = true;
                    }
                }
                if (bandera)
                {
                    await bookService.BookAuthorCreate(newBook.Id, newAuthor.Id);
                }
            }
            return(true);
        }
예제 #2
0
        /// <summary>
        /// Funcion que se encarga de realizar el logueo del usuario al sistema
        /// </summary>
        /// <param name="userName">Nombre de Usuario</param>
        /// <param name="passWord">Password del usuario</param>
        /// <returns></returns>
        public async Task <User> Login(string userName, string passWord)
        {
            var users = await FakeRestAPI.GetUser();

            if (users.Any(x => x.UserName == userName && x.Password == passWord))
            {
                var user = users.FirstOrDefault();
                return(new User()
                {
                    Id = user.Id,
                    UserName = user.UserName,
                    Password = user.Password
                });
            }
            return(null);
        }
예제 #3
0
        /// <summary>
        /// Funcion que retorna la cantidad de usuarios en el servicio externo
        /// </summary>
        /// <returns>Cantidad de usuarios</returns>
        public async Task <int> UsersCount()
        {
            var users = await FakeRestAPI.GetUser();

            return(users.Count());
        }