public async Task <IActionResult> CreateSchema([FromBody] CompensationSchema item) { if (item == null) { return(this.BadRequest()); } await this.unitOfWork.CompensationSchemaRepository.AddAsync(item); await this.unitOfWork.SaveAsync(); return(this.CreatedAtRoute("GetSchema", new { id = item.Id }, item)); }
public async Task <IActionResult> EditSchema([FromBody] CompensationSchema item, int id) { if (item == null) { return(this.BadRequest()); } var schema = await this.unitOfWork.CompensationSchemaRepository.GetQuery(u => u.Id == id) .Include(s => s.Positions) .Include(s => s.PaymentVariables).ThenInclude(v => v.PaymentTables) .FirstOrDefaultAsync(); if (schema == null) { return(this.NotFound()); } schema.Name = item.Name; schema.StartDate = item.StartDate; schema.FinalDate = item.FinalDate; schema.PeriodicityId = item.PeriodicityId; item.PaymentVariables?.ForEach(variable => variable.CompensationSchema = schema); this.unitOfWork.CompensationSchemaRepository.AddRemoveUpdateCollectionItems( schema.PaymentVariables, item.PaymentVariables, v => v.Id); item.Positions.ForEach(p => p.CompensationSchemaId = id); this.unitOfWork.CompensationSchemaRepository.AddRemoveCollectionItems( schema.Positions, item.Positions, x => $"{x.Id}-{x.CompensationSchemaId}"); this.unitOfWork.CompensationSchemaRepository.Edit(schema); await this.unitOfWork.SaveAsync(); return(new NoContentResult()); }