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); }
public void UpdateGoal(GoalDto goalDto) { var goal = _db.Goals.Find(goalDto.Id); _mapper.Map(goalDto, goal); _db.SaveChanges(); }
public override async Task <Empty> UpdateGoal(GoalDto request, ServerCallContext context) { var goal = request.ToGoal(); await _kanbanRepository.StoreGoalAsync(goal); return(new Empty()); }
public Goal CreateGoal(GoalDto goalDto) { var newGoal = _mapper.Map <Goal>(goalDto); _db.Goals.Add(newGoal); _db.SaveChanges(); return(newGoal); }
public DeveloperDto(int id, string name, DevType devType, GoalDto goal, List <TaskToDoDto> tasksToDo) { Id = id; Name = name; DevType = devType; Goal = goal; TasksToDo = tasksToDo; }
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); }
public IHttpActionResult GetGoal(long id) { var b = gSvc.GetGoal(id); if (b == null) { return(NotFound()); } return(Ok(GoalDto.FromGoal(b))); }
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 }); }
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)); }
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"); } }
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))); }
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); }
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); }
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); }
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); }
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); }
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); } }
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); }
public async Task <IActionResult> UpdateGoalAsync( [FromRoute, Required] int id, [FromBody, Required] GoalDto dto) { return(Ok(await _repo.UpdateAsync(id, dto))); }
// GET: api/Goals public IEnumerable <GoalDto> GetGoals() { return(gSvc.GetGoals().Select(b => GoalDto.FromGoal(b))); }