Пример #1
0
        public async Task <PagedList <UserDTO> > GetUsers(TextDTO text)
        {
            if (text.Search == "undefined" || text.Search == null)
            {
                text.Search = "";
            }
            if (text.Role == null)
            {
                text.Role = new List <string>();
            }

            var roles = await rolesRepo.GetWithIncludeAsync();

            var entities = await userRepo.GetWithIncludeAsync(x => x.Name.Contains(text.Search) &&
                                                              ((text.Role.Count == 0) ? roles.Any(s => x.UserRole.Type.Contains(s.Type)) : text.Role.Any(s => x.UserRole.Type.Contains(s))));


            var dtos = _mapper.Map <IEnumerable <User>, IEnumerable <UserDTO> >(entities).ToList();

            for (int i = 0; i < dtos.Count(); i++)
            {
                dtos[i].UserPhoto = await imageService.GetImageAsync(dtos[i].Id);
            }
            var query = dtos.AsQueryable();

            return(new PagedList <UserDTO>(
                       query, text.PageNumber, pageSize));
        }
Пример #2
0
        public async Task <ExcecutorDTO> AddExcecutor(ExcecutorDTO user)
        {
            var task = await taskRepo.FindByIdAsync(user.TaskId);

            TaskHistory history = new TaskHistory();

            history.DateUpdated     = DateTime.Now;
            history.UpdatedByUser   = task.Customer;
            history.StartTaskStatus = await statusRepo.FindByIdAsync((int)task.TaskStatusId);

            task.ExecutorId  = user.ExcecutorId;
            task.UpdatedById = task.CustomerId;
            task.DateUpdated = DateTime.Now;

            var status = (await statusRepo.GetWithIncludeAsync(s => s.Type == "In progress")).FirstOrDefault();

            task.TaskStatusId = status.Id;

            history.FinalTaskStatus = await statusRepo.FindByIdAsync(status.Id);

            await taskRepo.UpdateAsync(task);

            await historyRepo.CreateAsync(history);

            return(user);
        }
Пример #3
0
        public async Task <PagedList <TaskDTO> > GetHistoryTaskByUser(int id, int page, string search, int priceTo, int priceFrom, string[] categ)
        {
            search = search ?? "";
            if (priceTo == 0)
            {
                priceTo = 999999;
            }
            if (categ.Length == 0)
            {
                categ = new string[] { "" }
            }
            ;
            var entities = await taskRepo.GetWithIncludeAsync(
                o => o.TaskStatusId == (int)StatusEnum.Done &&
                o.Title.Contains(search) &&
                o.Price <= priceTo &&
                o.Price >= priceFrom &&
                o.ExecutorId == id &&
                categ.Any(s => o.TaskCategory.Type.Contains(s)),

                p => p.TaskCategory, k => k.Comments
                );

            var dtos  = mapper.Map <IEnumerable <FreelanceLand.Models.Task>, IEnumerable <TaskDTO> >(entities);
            var query = dtos.AsQueryable();

            return(new PagedList <TaskDTO>(
                       query, page, pageSize));
        }

        const int pageSize = 10;
Пример #4
0
        public async Task <TaskPageDTO> EditTask(TaskPageDTO task)
        {
            FreelanceLand.Models.Task myTask = await taskRepo.FindByIdAsync(task.Id);

            myTask.Title          = task.Title;
            myTask.Description    = task.Description;
            myTask.Price          = task.Price;
            myTask.TaskCategoryId = (await categoryRepo.GetWithIncludeAsync(c => c.Type == task.TaskCategory))
                                    .FirstOrDefault().Id;
            myTask.DateUpdated = DateTime.Now;

            await taskRepo.UpdateAsync(myTask);

            return(mapper.Map <FreelanceLand.Models.Task, TaskPageDTO>(myTask));
        }
Пример #5
0
        public async Task <Ratings> RateUser(int UserId, int RateByUser, int Mark, int UserStatusId)
        {
            var rating = new Ratings();

            rating.UserId       = UserId;
            rating.RateByUser   = RateByUser;
            rating.Mark         = Mark;
            rating.UserStatusId = UserStatusId;
            await ratingRepo.CreateAsync(rating);

            var  countUsers = (await ratingRepo.GetWithIncludeAsync(x => x.UserId == UserId)).Count();
            var  rat        = (await ratingRepo.GetWithIncludeAsync(x => x.UserId == UserId)).Sum(y => y.Mark) / countUsers;
            User user       = await userRepo.FindByIdAsync(UserId);

            user.Rating = (int)rat;
            await userRepo.UpdateAsync(user);

            return(rating);
        }
Пример #6
0
        public async Task <IEnumerable <TaskDTO> > DragAndDropTaskByCustomer(int taskId, int customerId, string secondStatus)
        {
            //зміна статусу таску
            var result = (await taskRepo.FindByIdAsync(taskId));

            if ((await statusRepo.FindByIdAsync((int)result.TaskStatusId)).Type == "In progress")
            {
                result.ExecutorId = null;
            }

            var newStatus = (await statusRepo.GetWithIncludeAsync(s => s.Type == secondStatus)).FirstOrDefault();

            result.TaskStatusId = newStatus.Id;

            await taskRepo.UpdateAsync(result);

            //повернення зміненого масиву створених тасків замовником
            var dtos = await GetCreatedTaskByUser(customerId);

            return(dtos);
        }
Пример #7
0
        public async Task <IEnumerable <CommentDTO> > GetComments(int taskId)
        {
            List <Comment> myComments = (await commentRepo.GetWithIncludeAsync(task => task.TaskId == taskId,
                                                                               user => user.User)).ToList();
            List <CommentDTO> result = mapper.Map <List <Comment>, List <CommentDTO> > (myComments);

            for (int i = 0; i < result.Count(); i++)
            {
                result[i].Photo = await imageService.GetImageAsync(result[i].UserId);
            }

            return(result);
        }
Пример #8
0
        public async Task <TaskPageDTO> GetTaskDescription(int id)
        {
            var myTask = (await taskRepo.GetWithIncludeAsync(task => task.Id == id,
                                                             customer => customer.Customer,
                                                             category => category.TaskCategory,
                                                             status => status.TaskStatus,
                                                             history => history.TaskHistories,
                                                             excecutor => excecutor.Executor)).Where(o => o.Id == id).FirstOrDefault();

            var dtos = mapper.Map <FreelanceLand.Models.Task, TaskPageDTO>(myTask);

            dtos.CustomerPhoto = await imageService.GetImageAsync(dtos.CustomerId);

            dtos.ExcecutorPhoto = await imageService.GetImageAsync(dtos.ExcecutorId);

            return(dtos);
        }