Exemplo n.º 1
0
        private List <Work> GetWorksInsert(ShrimpCropManagementFactor dto)
        {
            TimeSpan days  = (TimeSpan)(dto.ToDate - dto.FromDate);
            var      lWork = new List <Work>();

            Work work = new Work();

            for (int i = 0; i <= days.TotalDays; i++)
            {
                work = dto.ToWork();
                work.ExecutionTime = ((DateTime)dto.ExecutionTime).AddDays(i);
                lWork.Add(work);
            }
            return(lWork);
        }
Exemplo n.º 2
0
        private async Task CreateWork(ShrimpCropManagementFactor dto, IDbTransaction transaction)
        {
            dto.CreatedBy = _sessionService.UserId;

            if (dto.Frequency == ShrimpCropFrequency.Onetime.ToString())
            {
                Work workOneTime = dto.ToWork();
                workOneTime.ExecutionTime = (DateTime)dto.ExecutionTime;
                await this.DatabaseConnectService.Connection.InsertAsync <Work>(workOneTime, x => x.AttachToTransaction(transaction));
            }
            else
            {
                var query = new StringBuilder();
                query.Append("INSERT INTO bys_main.bys_work(id, name, value , execution_time, shrimp_crop_management_factor_id, created_at, created_by, modified_at, modified_by, farming_location_id, shrimp_breed_id, curator, status)");
                query.Append("VALUES (@Id, @Name, @Value, @ExecutionTime, @ShrimpCropManagementFactorId, @CreatedAt, @CreatedBy, @ModifiedAt, @ModifiedBy, @FarmingLocationId, @ShrimpBreedId, @Curator, @Status)");

                var works = GetWorksInsert(dto);
                this.DatabaseConnectService.Connection.Execute(query.ToString(), works, transaction);
            }
        }