Ejemplo n.º 1
0
        public static GoalDto ToGoalDto(this Goal goal)
        {
            var goalDto = new GoalDto
            {
                Title      = goal.Title,
                Rank       = goal.Rank.Key,
                GoalStatus = goal.GoalStatus.Key,
                Deadline   = goal.Deadline.Ticks,
                IsDeleted  = goal.IsDeleted
            };

            if (goal.Id != null)
            {
                goalDto.Id = goal.Id;
            }

            if (goal.Label != null)
            {
                goalDto.LabelDto = new LabelDto
                {
                    LabelName = goal.Label.LabelName,
                    HexColor  = goal.Label.HexColor,
                };
            }

            goalDto.Subtasks.AddRange(goal.Subtasks.Select(s => new SubtaskDto {
                Title = s.Title
            }));

            return(goalDto);
        }
Ejemplo n.º 2
0
        public void UpdateGoal(GoalDto goalDto)
        {
            var goal = _db.Goals.Find(goalDto.Id);

            _mapper.Map(goalDto, goal);
            _db.SaveChanges();
        }
Ejemplo n.º 3
0
        public override async Task <Empty> UpdateGoal(GoalDto request, ServerCallContext context)
        {
            var goal = request.ToGoal();
            await _kanbanRepository.StoreGoalAsync(goal);

            return(new Empty());
        }
Ejemplo n.º 4
0
        public Goal CreateGoal(GoalDto goalDto)
        {
            var newGoal = _mapper.Map <Goal>(goalDto);

            _db.Goals.Add(newGoal);
            _db.SaveChanges();
            return(newGoal);
        }
Ejemplo n.º 5
0
 public DeveloperDto(int id, string name, DevType devType, GoalDto goal, List <TaskToDoDto> tasksToDo)
 {
     Id        = id;
     Name      = name;
     DevType   = devType;
     Goal      = goal;
     TasksToDo = tasksToDo;
 }
Ejemplo n.º 6
0
        public static bool EqualValues(this GoalDto goalDto, Goal goal)
        {
            bool equal = goalDto.ID == goal.ID &&
                         goalDto.Field == goal.Field &&
                         goalDto.Name == goal.Name &&
                         goalDto.Threshold == goal.Threshold;

            return(equal);
        }
Ejemplo n.º 7
0
        public IHttpActionResult GetGoal(long id)
        {
            var b = gSvc.GetGoal(id);

            if (b == null)
            {
                return(NotFound());
            }
            return(Ok(GoalDto.FromGoal(b)));
        }
Ejemplo n.º 8
0
        public override async Task <GoalAdded> AddGoal(GoalDto request, ServerCallContext context)
        {
            var goal = request.ToGoal();
            await _kanbanRepository.StoreGoalAsync(goal);

            request.Id = goal.Id;

            return(new GoalAdded
            {
                Goal = request
            });
        }
Ejemplo n.º 9
0
 public async Task <IGoal> GetAsync(
     GoalDto dto,
     bool asNoTracking = true)
 {
     return(await GetQuery(asNoTracking)
            .FirstOrDefaultAsync(x => x.Name == dto.Name &&
                                 x.Type == dto.Type &&
                                 x.Amount == dto.Amount &&
                                 x.CurrentAmount == dto.CurrentAmount &&
                                 x.MonthlyContribution == dto.MonthlyContribution &&
                                 x.PlannedDate == dto.PlannedDate &&
                                 x.ProjectedDate == dto.ProjectedDate));
 }
Ejemplo n.º 10
0
 private async Task CheckAsync(
     GoalDto dto,
     string message = null)
 {
     if (dto == null)
     {
         throw new AiofFriendlyException(HttpStatusCode.BadRequest, message ?? $"Goal DTO cannot be NULL");
     }
     else if (await GetAsync(dto) != null)
     {
         throw new AiofFriendlyException(HttpStatusCode.BadRequest, message ?? $"Goal already exists");
     }
 }
Ejemplo n.º 11
0
        public IHttpActionResult PostGoal(Goal goal)
        {
            var uid = User.Identity.GetUserId();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            gSvc.CreateGoal(goal, uid);
            uow.Save();

            return(CreatedAtRoute("DefaultApi", new { id = goal.ID }, GoalDto.FromGoal(goal)));
        }
Ejemplo n.º 12
0
        public async Task <IGoal> AddAsync(GoalDto dto)
        {
            var goal = _mapper.Map <Goal>(dto);

            goal.UserId = _context.Tenant.UserId;

            goal.ProjectedDate = CalculateProjectedDate(
                goal.Amount,
                goal.CurrentAmount,
                goal.MonthlyContribution);

            await _context.Goals.AddAsync(goal);

            await _context.SaveChangesAsync();

            return(goal);
        }
Ejemplo n.º 13
0
        public static Goal ToGoal(this GoalDto goalDto)
        {
            var rank     = Rank.Create(goalDto.Rank).Value;
            var status   = GoalStatus.Create(goalDto.GoalStatus).Value;
            var deadline = new DateTime(goalDto.Deadline);
            var subtasks = goalDto.Subtasks.Select(s => Subtask.Create(s.Title).Value);

            var goal = Goal.Create(goalDto.Title, rank, status, subtasks, deadline).Value;

            goal.Id        = string.IsNullOrEmpty(goalDto.Id) ? null : goalDto.Id;
            goal.IsDeleted = goalDto.IsDeleted;
            if (goalDto.LabelDto != null)
            {
                var label = Label.Create(goalDto.LabelDto.LabelName, goalDto.LabelDto.HexColor).Value;
                goal.SetLabel(label);
            }
            return(goal);
        }
Ejemplo n.º 14
0
        public bool CreateGoal(GoalDto goal)
        {
            var existUser = unit.Users.FindByCondition(x => x.UserId.Equals(goal.UserId)).Count();

            if (existUser == 0)
            {
                return(false);
            }

            var newGoal = mapper.Map <DAL.Models.Goal>(goal);

            newGoal.GoalId = Guid.NewGuid();
            newGoal.User   = unit.Users.FindByCondition(u => u.UserId.Equals(newGoal.UserId)).FirstOrDefault();
            newGoal.Coach  = unit.Coaches.FindByCondition(c => c.CoachId.Equals(newGoal.CoachId)).FirstOrDefault();

            unit.Goals.Create(newGoal);
            unit.Save();
            return(true);
        }
Ejemplo n.º 15
0
        public bool DeleteGoal(GoalDto goal)
        {
            var existGoal = unit.Goals.FindByCondition(x => x.GoalId.Equals(goal.GoalId)).Count();

            if (existGoal == 0)
            {
                return(false);
            }

            var delGoal = mapper.Map <DAL.Models.Goal>(goal);

            delGoal.User     = unit.Users.FindByCondition(u => u.UserId.Equals(delGoal.UserId)).FirstOrDefault();
            delGoal.Coach    = unit.Coaches.FindByCondition(c => c.CoachId.Equals(delGoal.CoachId)).FirstOrDefault();
            delGoal.Subgoals = unit.Subgoals.FindByCondition(s => s.GoalId.Equals(delGoal.GoalId)).ToList();

            unit.Goals.Delete(delGoal);
            unit.Save();
            return(true);
        }
Ejemplo n.º 16
0
        public async Task CreateCampaign()
        {
            DateTime goalStart = new DateTime();
            DateTime goalEnd   = new DateTime();

            var goal = new GoalDto {
                GoalStart = goalStart,
                GoalEnd   = goalEnd,
                MinAmount = 1337
            };

            var data = new CampaignDto {
                CampaignName        = "campaign controller test",
                CampaignDescription = "the description for the campaign created in the controller test",
                Goal = goal
            };

            var result = await CreateCampaignRequest(data);

            Assert.Equal("campaign controller test", result.CampaignName);
        }
Ejemplo n.º 17
0
        public void TestCreateGoal()
        {
            var options = new DbContextOptionsBuilder <MyPracticeJournalContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;

            using (var db = new  MyPracticeJournalContext(options))
            {
                var goalService = new GoalService(_mapper, db);
                var goalDto     = new GoalDto
                {
                    Name        = "One",
                    Description = "Desc One"
                };
                goalService.CreateGoal(goalDto);
            }

            using (var db = new  MyPracticeJournalContext(options))
            {
                Assert.AreEqual(1, db.Goals.Count());
                Assert.AreEqual("One", db.Goals.Single().Name);
            }
        }
Ejemplo n.º 18
0
        public async Task <IGoal> UpdateAsync(
            int id,
            GoalDto dto)
        {
            await CheckAsync(dto);

            var goal = await GetAsync(id, false);

            var goalToUpdate = _mapper.Map(dto, goal as Goal);

            _context.Goals
            .Update(goalToUpdate);

            await _context.SaveChangesAsync();

            _logger.LogInformation("{Tenant} | Updated Goal with Id={GoalId}, PublicKey={GoalPublicKey} and UserId={GoalUserId}",
                                   _context.Tenant.Log,
                                   goal.Id,
                                   goal.PublicKey,
                                   goal.UserId);

            return(goal);
        }
Ejemplo n.º 19
0
 public async Task <IActionResult> UpdateGoalAsync(
     [FromRoute, Required] int id,
     [FromBody, Required] GoalDto dto)
 {
     return(Ok(await _repo.UpdateAsync(id, dto)));
 }
Ejemplo n.º 20
0
 // GET: api/Goals
 public IEnumerable <GoalDto> GetGoals()
 {
     return(gSvc.GetGoals().Select(b => GoalDto.FromGoal(b)));
 }