public IActionResult AddActionForPlant([FromBody] PlantsActionDto actionDto) { var user = _userAuthService.GetUser(actionDto.UserId); _scheduledActionService.AddPlantsAction(user, actionDto); return(Ok()); }
public void UpdateDate(PlantsActionDto dto) { var audit = _dbContext.PlantsAudit .FirstOrDefault(x => x.Id == dto.Id); audit.ScheduledDate = dto.ScheduledDate; _dbContext.SaveChanges(); }
public IActionResult MarkAsDone(int actionId) { PlantsActionDto dto = new PlantsActionDto(); dto.Id = actionId; _scheduledActionService.MarkAsDone(dto); return(Ok()); }
public void MarkAsDone(PlantsActionDto dto) { var audit = _dbContext.PlantsAudit .FirstOrDefault(x => x.Id == dto.Id); audit.ExecutionDate = dto.ExecutionDate; audit.IsDone = true; _dbContext.SaveChanges(); }
public static ScheduledAction ToEntity(this PlantsActionDto dto) { ScheduledAction action = new ScheduledAction() { PlantId = dto.PlantId, ScheduledDate = dto.ScheduledDate, AmountOfWaterMilliliters = dto.AmountOfWaterMilliliters, }; return(action); }
public void AddPlantsAction(User user, PlantsActionDto plantsActionDto) { if (plantsActionDto.Days != Days.NONE) { try { var plant = _dbContext.Plants.FirstOrDefault(x => x.Id == plantsActionDto.PlantId); var rule = new Rule() { Days = plantsActionDto.Days, WaterInMilliliters = plantsActionDto.AmountOfWaterMilliliters, }; plant.Rule = rule; } catch (Exception e) { Console.WriteLine(e); } } var action = new ScheduledAction { ImagePath = plantsActionDto.ImageUri, AmountOfWaterMilliliters = plantsActionDto.AmountOfWaterMilliliters, ScheduledDate = plantsActionDto.ScheduledDate }; action.PlantId = plantsActionDto.PlantId; user.PlantsAudits.Add(action); _dbContext.SaveChanges(); var rules = _dbContext.Rules.ToString(); }
public static PlantsActionDto ToDto(this ScheduledAction action) { var imageUri = action.Plant?.ImageUri; if (string.IsNullOrEmpty(imageUri) && action.Plant.PlantInfo != null) { imageUri = action.Plant?.PlantInfo?.ImageUri; } PlantsActionDto dto = new PlantsActionDto() { Recommendations = action.Recommendation, Id = action.Id, Name = action.Plant.Name, ImageUri = imageUri, ImageName = action.Plant.ImageName, PlantId = action.Plant.Id, ScheduledDate = action.ScheduledDate, AmountOfWaterMilliliters = action.AmountOfWaterMilliliters, ExecutionDate = action.ExecutionDate }; return(dto); }
public IActionResult UpdateScheduledDate(int actionId, [FromBody] PlantsActionDto dto) { dto.Id = actionId; _scheduledActionService.UpdateDate(dto); return(Ok()); }