public ActionResult Add(Goal goal) { try { if (ModelState.IsValid) { goal.CreatedBy = HttpContext.User.Identity.Name; goal = goalRepository.Add(goal); return(Redirect("/Goals/")); } else { ViewBag.ErrorMessage = "There is a problem with one of your response."; } } catch (Exception ex) { ViewBag.ErrorMessage = "An Error Occurred while attempting to save that goal."; } ViewBag.ActionName = "Add"; ViewBag.Title = "Add a Goal"; return(View("EditGoal", goal)); }
public async Task CreateAsync(Goal goal) { _goalRepository.Add(goal); var match = await _matchRepository.GetAsync(goal.MatchId); match.IsPlayed = true; await _unitOfWork.CompleteAsync(); }
public new Recurrent Add(Recurrent item) { if (item == null) { throw new ArgumentNullException("item"); } base.Add(item); item.Goal.ParentId = item.Id; item.Goal.ParentTypeId = GoalEntityType.Recurrent; _goalRepository.Add(item.Goal); return(item); }
public void CreateJob(JobLocationRequest jobLocationRequest) { try { var locationStart = _locationRepository.Get(jobLocationRequest.Start); var locationDestination = _locationRepository.Get(jobLocationRequest.Destination); if (locationStart == null || locationDestination == null) { throw new Exception("No location found"); } var job = new Job() { Status = JobStatus.StatusPending, CreatedDate = DateTime.Now }; _jobRepository.Add(job); var startGoal = new Goal() { JobId = job.JobId, LocationId = jobLocationRequest.Start, Status = "pending" }; var destinationGoal = new Goal() { JobId = job.JobId, LocationId = jobLocationRequest.Destination, Status = "pending" }; _goalRepository.Add(startGoal); _goalRepository.Add(destinationGoal); } catch (Exception e) { throw new Exception(e.ToString()); } }
public async Task <IActionResult> CreateGoal([FromBody] SaveGoalResource goalResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var goal = _mapper.Map <SaveGoalResource, Goal>(goalResource); _repository.Add(goal); await _unitOfWork.CompleteAsync(); //Repository call goal = await _repository.GetGoalByIdWithRelations(goal.Id); var result = _mapper.Map <Goal, GoalResource>(goal); InvokeHub(); return(Ok(result)); }
public async Task <bool> Handle(RegisterNewGoalCommand message, CancellationToken cancellationToken) { if (!message.IsValid()) { NotifyValidationErrors(message); return(false); } var goal = new Goal(message.Description, message.Reward, message.StarsToAchieve, message.StarsEarned, message.StartDate, message.EndDate); if (_goalRepository.GetById(goal.Id) != null) { await Bus.RaiseEvent(new DomainNotification(message.MessageType, "The Goal e-mail has already been taken.")); return(false); } _goalRepository.Add(goal); if (await Commit()) { await Bus.RaiseEvent(new GoalRegisteredEvent(goal.Id, goal.Description, goal.Reward, goal.StarsToAchieve, goal.StarsEarned, goal.StartDate, goal.EndDate)); } return(true); }
public async Task <RequestResult <GoalDto> > Handle(AddGoal request, CancellationToken cancellationToken) { var result = new RequestResult <GoalDto>(); var user = UserRepository .GetAllWithCollections() .FirstOrDefault(u => u.Id == request.UserId); if (user is null) { result.AddError($"User with id {request.UserId} was not found", HttpStatusCode.NotFound); return(result); } if (user.Goals.Count >= 3) { result.AddError("User already have maximum (3) goals, remove other to make storage", HttpStatusCode.Forbidden); return(result); } var goal = new Goal() { Id = Guid.NewGuid().ToString(), CreatedAt = DateTime.UtcNow, Name = request.Name, TargetValue = request.TargetValue, User = user }; GoalRepository.Add(goal); GoalRepository.SaveChanges(); result.SetSingleItem(Mapper.Map <GoalDto>(goal)); result.StatusCode = HttpStatusCode.OK; return(result); }
public void CreateGoal(Goal goal) { _goalRepository.Add(goal); SaveGoal(); }
public Goal Add(Goal goal) { var dbGoal = _goalRepository.Add(goal); return(dbGoal); }
public void Post([FromBody] Goal goal) { goalRepository.Add(goal); }