Пример #1
0
        public ResponseResults <NewsLetterViewModel> GetNewsLetters(SearchNewLetterViewModel searchParam)
        {
            var response = new ResponseResults <NewsLetterViewModel> {
                IsSucceed = true, Message = AppMessages.RETRIEVED_DETAILS_SUCCESSFULLY
            };

            try
            {
                var models = UnitOfWork.NewsLetterRepository.GetNewsLetters(searchParam);
                response.ViewModels = models.ToViewModel <NewsLetterEntityModel, NewsLetterViewModel>().ToList();

                if (response.ViewModels != null && response.ViewModels.Count > 0 && searchParam.UserId > 0)
                {
                    var userNewsLetterLookUp = UnitOfWork.UserNewsLetterRepository.Get(o => o.UserId == searchParam.UserId);
                    if (userNewsLetterLookUp != null && userNewsLetterLookUp.NewsLetterIds != null && userNewsLetterLookUp.NewsLetterIds.Length > 0)
                    {
                        response.ViewModels.ForEach(o => o.IsSubscribed = userNewsLetterLookUp.NewsLetterIds.Contains(o.Id.ToString()));
                    }
                }

                if (response.ViewModels.Count <= 0)
                {
                    response.Message = AppMessages.NO_RECORD_FOUND;
                }
            }
            catch (Exception ex)
            {
                response.IsSucceed = false;
                response.Message   = ex.Message;
            }
            return(response);
        }
Пример #2
0
        public ResponseResults <NewsLetterViewModel> GetUserNewsLetters(long userId)
        {
            var response = new ResponseResults <NewsLetterViewModel> {
                IsSucceed = true, ViewModels = new List <NewsLetterViewModel>(), Message = AppMessages.RETRIEVED_DETAILS_SUCCESSFULLY
            };

            try
            {
                if (userId > 0)
                {
                    var userNewsLettrs = UnitOfWork.UserNewsLetterRepository.FindByUser(userId);
                    if (userNewsLettrs != null && userNewsLettrs.NewsLetterIds != null && userNewsLettrs.NewsLetterIds.Length > 0)
                    {
                        var longIds = AppMethods.StringToLongList(userNewsLettrs.NewsLetterIds);

                        var models = UnitOfWork.NewsLetterRepository.GetNewsLettersByIds(longIds);
                        response.ViewModels = models.ToViewModel <NewsLetterEntityModel, NewsLetterViewModel>().ToList();
                    }
                }

                if (response.ViewModels.Count <= 0)
                {
                    response.Message = AppMessages.NO_RECORD_FOUND;
                }
            }
            catch (Exception ex)
            {
                response.IsSucceed = false;
                response.Message   = ex.Message;
            }
            return(response);
        }
Пример #3
0
        public ResponseResults <BookViewModel> GetBooks(SearchBookViewModel searchParam)
        {
            var response = new ResponseResults <BookViewModel> {
                IsSucceed = true, Message = AppMessages.RETRIEVED_DETAILS_SUCCESSFULLY
            };

            try
            {
                var models = UnitOfWork.BookRepository.GetBooks(searchParam);
                response.ViewModels = models.ToViewModel <BookEntityModel, BookViewModel>().ToList();

                if (!string.IsNullOrWhiteSpace(searchParam.UserName))
                {
                    var user = UnitOfWork.UserRepository.FindByUserName(searchParam.UserName);
                    var demandedBookLookUp = UnitOfWork.UserDemandRepository.GetMany(o => o.UserId == user.Id).Select(o => o.BookId).ToList();
                    response.ViewModels.ForEach(o => o.IsRequested = demandedBookLookUp.Contains(o.Id));
                }

                if (response.ViewModels.Count <= 0)
                {
                    response.Message = AppMessages.NO_RECORD_FOUND;
                }
            }
            catch (Exception ex)
            {
                response.IsSucceed = false;
                response.Message   = ex.Message;
            }
            return(response);
        }
        public ResponseResults <LookUpViewModel> GetLookup()
        {
            var response = new ResponseResults <LookUpViewModel> {
                IsSucceed = true, Message = AppMessages.Retrieved_Details_Successfully
            };

            try
            {
                var entities = UnitOfWork.CountryRepository.GetAll();
                if (entities != null && entities.Count > 0)
                {
                    response.ViewModels = entities.Select(o => new LookUpViewModel {
                        Id = o.Id, Value = o.CountryName
                    }).ToList();
                }

                if (entities != null && entities.Count <= 0)
                {
                    response.Message = AppMessages.No_Record_Found;
                }
            }
            catch (Exception ex)
            {
                NLogLogger.Instance.Log(ex.Message);
            }
            return(response);
        }
Пример #5
0
        public ResponseResults <BookViewModel> GetTop10(string userName)
        {
            var response = new ResponseResults <BookViewModel>()
            {
                IsSucceed = true, Message = AppMessages.RETRIEVED_DETAILS_SUCCESSFULLY
            };

            try
            {
                var models = UnitOfWork.SetDbContext(BaseRepository).PageAll(0, 10);
                response.ViewModels = models.ToViewModel <BookEntityModel, BookViewModel>().ToList();

                if (!string.IsNullOrWhiteSpace(userName))
                {
                    var user = UnitOfWork.UserRepository.FindByUserName(userName);
                    var demandedBookLookUp = UnitOfWork.UserDemandRepository.GetMany(o => o.UserId == user.Id).Select(o => o.BookId).ToList();
                    response.ViewModels.ForEach(o => o.IsRequested = demandedBookLookUp.Contains(o.Id));
                }
            }
            catch (Exception ex)
            {
                response.IsSucceed = false;
                response.Message   = ex.Message;
            }
            return(response);
        }
Пример #6
0
        public static Mock <IUserNewsLetterService> GetMockService()
        {
            GetReadOnlyNewsLetterData();
            GetReadOnlyUserData();
            GetReadOnlyUserNewsLetterData();
            GetReadOnlyNewsLetterData();

            var mockService = new Mock <IUserNewsLetterService>();

            mockService.Setup(a => a.GetUserNewsLetters(It.IsAny <long>())).Returns <long>(userId =>
            {
                var response = new ResponseResults <NewsLetterViewModel> {
                    IsSucceed = true, ViewModels = new System.Collections.Generic.List <NewsLetterViewModel>(), Message = AppMessages.RETRIEVED_DETAILS_SUCCESSFULLY
                };

                if (userId > 0)
                {
                    var model = userNewsLetterDataCollection.FirstOrDefault(o => o.UserId == userId);
                    if (model != null && model.NewsLetterIds.Length > 0)
                    {
                        var longIds         = AppMethods.StringToLongList(model.NewsLetterIds);
                        var models          = newsLetterDataCollection.Where(o => longIds.Contains(o.Id));
                        response.ViewModels = models.ToViewModel <NewsLetterEntityModel, NewsLetterViewModel>().ToList();
                    }
                }

                if (response.ViewModels.Count <= 0)
                {
                    response.Message = AppMessages.NO_RECORD_FOUND;
                }
                return(response);
            });

            return(mockService);
        }
        public virtual ResponseResults <VM> GetAll()
        {
            var response = new ResponseResults <VM>()
            {
                IsSucceed = true, Message = AppMessages.Retrieved_Details_Successfully
            };

            try
            {
                var models = baseRepository.GetAll();
                response.ViewModels = models.ToViewModel <T, VM>().ToList();
            }
            catch (Exception ex)
            {
                response.IsSucceed = false;
                response.Message   = ex.Message;
            }
            return(response);
        }
        public override ResponseResults <VM> GetAll()
        {
            var response = new ResponseResults <VM>()
            {
                IsSucceed = true, Message = AppMessages.Retrieved_Details_Successfully
            };

            try
            {
                var models = UnitOfWork.SetDbContext(IdentityBaseRepository).GetAll();
                response.ViewModels = models.ToViewModel <T, VM>().ToList();
            }
            catch (Exception ex)
            {
                response.IsSucceed = false;
                response.Message   = ex.Message;
            }
            return(response);
        }
Пример #9
0
        public virtual ResponseResults <VM> GetAll()
        {
            var response = new ResponseResults <VM>()
            {
                IsSucceed = true, Message = AppMessages.RETRIEVED_DETAILS_SUCCESSFULLY
            };

            try
            {
                var models = UnitOfWork.SetDbContext(BaseRepository).GetAll();
                response.ViewModels = models.ToViewModel <T, VM>().ToList();
            }
            catch (Exception ex)
            {
                response.IsSucceed = false;
                response.Message   = ex.Message;
            }
            return(response);
        }
        public ResponseResults <UserDemandDetailViewModel> GetUserDemands(string userName)
        {
            var response = new ResponseResults <UserDemandDetailViewModel> {
                IsSucceed = true, ViewModels = new System.Collections.Generic.List <UserDemandDetailViewModel>(), Message = AppMessages.RETRIEVED_DETAILS_SUCCESSFULLY
            };

            try
            {
                if (!string.IsNullOrWhiteSpace(userName))
                {
                    var user   = UnitOfWork.UserRepository.FindByUserName(userName);
                    var models = UnitOfWork.UserDemandRepository.GetUserDemands(user.Id).ToList();
                    if (models != null && models.Count > 0)
                    {
                        var bookIds    = models.Select(o => o.BookId).ToList();
                        var bookLookUp = UnitOfWork.BookRepository.GetMany(o => bookIds.Contains(o.Id)).ToDictionary(o => o.Id, o => o.Title);
                        response.ViewModels = models.Select(o => new UserDemandDetailViewModel
                        {
                            BookId        = o.BookId,
                            IssuedDate    = o.IssuedDate,
                            ReturnedDate  = o.ReturnedDate,
                            Remark        = o.Remark,
                            UpdatedOn     = o.UpdatedOn,
                            UserId        = o.UserId,
                            RequestStatus = (o.RequestStatus) ? "Approved" : "Pending",
                            BookTitle     = bookLookUp[o.BookId]
                        }).ToList();
                    }
                }

                if (response.ViewModels.Count <= 0)
                {
                    response.Message = AppMessages.NO_RECORD_FOUND;
                }
            }
            catch (Exception ex)
            {
                response.IsSucceed = false;
                response.Message   = ex.Message;
            }
            return(response);
        }
        public static Mock <IUserDemandService> GetMockService()
        {
            GetReadOnlyBookData();
            GetReadOnlyUserData();
            GetReadOnlyUserDemandData();

            var mockService = new Mock <IUserDemandService>();

            mockService.Setup(a => a.GetUserDemands(It.IsAny <string>())).Returns <string>(userName =>
            {
                var response = new ResponseResults <UserDemandDetailViewModel> {
                    IsSucceed = true, ViewModels = new System.Collections.Generic.List <UserDemandDetailViewModel>(), Message = AppMessages.RETRIEVED_DETAILS_SUCCESSFULLY
                };

                if (!string.IsNullOrWhiteSpace(userName))
                {
                    var user   = userDataCollection.FirstOrDefault(o => o.UserName == userName);
                    var models = userDemandDataCollection.Where(o => o.UserId == user.Id).ToList();
                    if (models != null && models.Count > 0)
                    {
                        var bookIds         = models.Select(o => o.BookId).ToList();
                        var bookLookUp      = bookDataCollection.Where(o => bookIds.Contains(o.Id)).ToDictionary(o => o.Id, o => o.Title);
                        response.ViewModels = models.Select(o => new UserDemandDetailViewModel
                        {
                            BookId        = o.BookId,
                            IssuedDate    = o.IssuedDate,
                            ReturnedDate  = o.ReturnedDate,
                            Remark        = o.Remark,
                            UpdatedOn     = o.UpdatedOn,
                            UserId        = o.UserId,
                            RequestStatus = (o.RequestStatus) ? "Approved" : "Pending",
                            BookTitle     = bookLookUp[o.BookId]
                        }).ToList();
                    }
                }

                if (response.ViewModels.Count <= 0)
                {
                    response.Message = AppMessages.NO_RECORD_FOUND;
                }
                return(response);
            });

            mockService.Setup(a => a.DemandBook(It.IsAny <string>(), It.IsAny <string>())).Returns <string, string>((bookId, userName) =>
            {
                var response = new BaseResponseResult {
                    IsSucceed = true, Message = AppMessages.RETRIEVED_DETAILS_SUCCESSFULLY
                };

                if (!string.IsNullOrWhiteSpace(userName))
                {
                    var user        = userDataCollection.FirstOrDefault(o => o.UserName == userName);
                    var entityModel = new UserDemandEntityModel
                    {
                        BookId        = ObjectId.Parse(bookId),
                        UserId        = user.Id,
                        RequestStatus = false,
                        UpdatedBy     = user.Id,
                        UpdatedOn     = DateTime.Now
                    };
                    userDemandDataCollection.Add(entityModel);
                }
                else
                {
                    response.IsSucceed = false;
                    response.Message   = AppMessages.INVALID_INPUT;
                }

                return(response);
            });

            return(mockService);
        }
Пример #12
0
        public static Mock <INewsLetterService> GetMockService()
        {
            GetReadOnlyNewsLetterData();
            GetReadOnlyUserData();
            GetReadOnlyUserNewsLetterData();

            var mockService = new Mock <INewsLetterService>();

            mockService.Setup(a => a.GetTopNewsLetters(It.IsAny <long>())).Returns <long>(userId =>
            {
                var response = new ResponseResults <ViewModels.NewsLetterViewModel>()
                {
                    IsSucceed = true, ViewModels = new List <ViewModels.NewsLetterViewModel>(), Message = AppMessages.RETRIEVED_DETAILS_SUCCESSFULLY
                };

                response.ViewModels = newsLetterDataCollection.Take(10).ToViewModel <NewsLetterEntityModel, NewsLetterViewModel>().ToList();

                if (userId > 0)
                {
                    var newsLetterIds = userNewsLetterDataCollection.FirstOrDefault(o => o.UserId == userId).NewsLetterIds;
                    var longIds       = AppMethods.StringToLongList(newsLetterIds);

                    response.ViewModels.ForEach(o => o.IsSubscribed = longIds.Contains(o.Id));
                }

                if (response.ViewModels.Count <= 0)
                {
                    response.Message = AppMessages.NO_RECORD_FOUND;
                }
                return(response);
            });

            mockService.Setup(a => a.GetNewsLetters(It.IsAny <SearchNewLetterViewModel>())).Returns <SearchNewLetterViewModel>(searchParam =>
            {
                var query    = newsLetterDataCollection.AsQueryable();
                var response = new ResponseResults <NewsLetterViewModel>()
                {
                    IsSucceed = true, ViewModels = new List <NewsLetterViewModel>(), Message = AppMessages.RETRIEVED_DETAILS_SUCCESSFULLY
                };

                if (!string.IsNullOrWhiteSpace(searchParam.Publisher))
                {
                    query = query.Where(o => o.Publisher.ToLower().Trim().Contains(searchParam.Publisher.ToLower().Trim()));
                }

                if (!string.IsNullOrWhiteSpace(searchParam.Author))
                {
                    query = query.Where(o => o.Author.Contains(searchParam.Author.Trim()));
                }

                var models = query.ToList();
                if (models != null && models.Count > 0)
                {
                    response.ViewModels = models.ToViewModel <NewsLetterEntityModel, NewsLetterViewModel>().ToList();
                    if (searchParam.UserId > 0)
                    {
                        var newsLetterIds = userNewsLetterDataCollection.FirstOrDefault(o => o.UserId == searchParam.UserId).NewsLetterIds;
                        var longIds       = AppMethods.StringToLongList(newsLetterIds);

                        response.ViewModels.ForEach(o => o.IsSubscribed = longIds.Contains(o.Id));
                    }
                }

                if (response.ViewModels.Count <= 0)
                {
                    response.Message = AppMessages.NO_RECORD_FOUND;
                }
                return(response);
            });

            return(mockService);
        }
 /// <summary>
 /// Updates the response and response result.
 /// </summary>
 /// <param name="result">The result of waiting for the response.</param>
 /// <param name="response">The response message.</param>
 internal void ResponseReceived(ResponseResults result, Message response)
 {
     lock (_lockObject)
     {
         _responseResult = result;
         _responseMessage = response;
         _progress = MessageResponseProgress.Completed;
     }
 }
Пример #14
0
 public ModelBase()
 {
     ResponseResult = new ResponseResults();
 }
Пример #15
0
        public static Mock <ISearchBookService> GetMockService()
        {
            GetReadOnlyBookData();
            GetReadOnlyUserData();
            GetReadOnlyUserDemandData();

            var mockService = new Mock <ISearchBookService>();

            mockService.Setup(a => a.GetBooks(It.IsAny <SearchBookViewModel>())).Returns <SearchBookViewModel>(searchParam =>
            {
                var query    = bookDataCollection.AsQueryable();
                var response = new ResponseResults <BookViewModel>()
                {
                    IsSucceed = true, ViewModels = new List <BookViewModel>(), Message = AppMessages.RETRIEVED_DETAILS_SUCCESSFULLY
                };

                if (!string.IsNullOrWhiteSpace(searchParam.Title))
                {
                    query = query.Where(o => o.Title.ToLower().Trim().Contains(searchParam.Title.ToLower().Trim()));
                }

                if (!string.IsNullOrWhiteSpace(searchParam.Author))
                {
                    query = query.Where(o => o.Authors.Contains(searchParam.Author.Trim()));
                }

                var models = query.ToList();
                if (models != null && models.Count > 0)
                {
                    response.ViewModels = models.ToViewModel <BookEntityModel, BookViewModel>().ToList();
                    if (!string.IsNullOrWhiteSpace(searchParam.UserName))
                    {
                        var user = userDataCollection.FirstOrDefault(o => o.UserName == searchParam.UserName);
                        if (user != null)
                        {
                            var demandedBookLookUp = userDemandDataCollection.Where(o => o.UserId == user.Id).Select(o => o.BookId).ToList();
                            response.ViewModels.ForEach(o => o.IsRequested = demandedBookLookUp.Contains(o.Id));
                        }
                    }
                }

                if (response.ViewModels.Count <= 0)
                {
                    response.Message = AppMessages.NO_RECORD_FOUND;
                }
                return(response);
            });

            mockService.Setup(a => a.GetTop10(It.IsAny <string>())).Returns <string>(userName =>
            {
                var response = new ResponseResults <BookViewModel>()
                {
                    IsSucceed = true, ViewModels = new List <BookViewModel>(), Message = AppMessages.RETRIEVED_DETAILS_SUCCESSFULLY
                };

                response.ViewModels = bookDataCollection.Take(10).ToViewModel <BookEntityModel, BookViewModel>().ToList();
                if (!string.IsNullOrWhiteSpace(userName))
                {
                    var user = userDataCollection.FirstOrDefault(o => o.UserName == userName);
                    if (user != null)
                    {
                        var demandedBookLookUp = userDemandDataCollection.Where(o => o.UserId == user.Id).Select(o => o.BookId).ToList();
                        response.ViewModels.ForEach(o => o.IsRequested = demandedBookLookUp.Contains(o.Id));
                    }
                }

                if (response.ViewModels.Count <= 0)
                {
                    response.Message = AppMessages.NO_RECORD_FOUND;
                }
                return(response);
            });

            return(mockService);
        }
Пример #16
0
 public ModelBase()
 {
     ResponseResult = new ResponseResults();
 }
 public JsonResponse(ResponseResults result, string description = "", string requestId = "")
 {
     Result      = result;
     Description = description;
 }
Пример #18
0
 /// <summary>
 /// Sets the response result.
 /// </summary>
 /// <param name="result">The result to set it to.</param>
 /// <param name="response">The response message that was received.</param>
 public void SetMessageResponseResult(ResponseResults result, Message response)
 {
     if (_responseResult != null)
     {
         _responseResult.ResponseReceived(result, response);
     }
 }
 /// <summary>
 /// Updates the send result.
 /// </summary>
 /// <param name="result">The result of sending the message.</param>
 internal void MessageSent(SendResults result)
 {
     lock (_lockObject)
     {
         _sendResult = result;
         if (result != SendResults.Success)
         {
             _responseResult = ResponseResults.ConnectionFailure;
             _progress = MessageResponseProgress.Completed;
         }
         else
         {
             _progress = MessageResponseProgress.WaitingForResponse;
         }
     }
 }