Exemplo n.º 1
0
        public async Task <int> CreateRatingAsync(RatingDTO rating)
        {
            using (var uow = UnitOfWorkProvider.Create())
            {
                if (rating.RatedUserRole == UserRole.Corporation)
                {
                    var corporation = await corporationService.GetAsync(rating.RatedUserId);

                    if (!corporation.SumRating.HasValue)
                    {
                        corporation.SumRating = 0;
                    }
                    corporation.SumRating   += rating.Score;
                    corporation.RatingCount += 1;
                    await corporationService.Update(corporation);
                }
                else
                {
                    var freelancer = await freelancerService.GetAsync(rating.RatedUserId);

                    if (!freelancer.SumRating.HasValue)
                    {
                        freelancer.SumRating = 0;
                    }
                    freelancer.SumRating   += rating.Score;
                    freelancer.RatingCount += 1;

                    await freelancerService.Update(freelancer);
                }
                var ratingId = ratingService.Create(rating);
                await uow.Commit();

                return(ratingId);
            }
        }
 public IActionResult Put([FromBody] FreelancerVm model)
 {
     if (model.Id != 0)
     {
         return(Ok(_freelancer.Update(model)));
     }
     else
     {
         return(BadRequest("Some fields are empty"));
     }
 }
Exemplo n.º 3
0
        public async Task <bool> EditFreelancerAsync(FreelancerDTO freelancer)
        {
            using (var uow = UnitOfWorkProvider.Create())
            {
                if ((await freelancerService.GetAsync(freelancer.Id, false)) == null)
                {
                    return(false);
                }
                await freelancerService.Update(freelancer);

                await uow.Commit();

                return(true);
            }
        }