public HttpResult <Toggle> Create(Toggle toggle, List <int> idsServiceRota) { var retorno = new HttpResult <Toggle>(); _dbContext.Context.Toggle.Add(toggle); foreach (var id in idsServiceRota) { var retornoServiceRotaGet = ServiceRotaEntityService.Get(id); if (retornoServiceRotaGet == null) { return(retorno.SetHttpStatusToNotFound()); } var toggleServiceRota = new ToggleServiceRota(); toggleServiceRota.ServiceRota = retornoServiceRotaGet.Result; toggleServiceRota.Toggle = toggle; toggle.ToggleServiceRotas.Add(toggleServiceRota); } _dbContext.SaveChanges(); retorno.Response = toggle; retorno.SetHttpStatusToCreated(); return(retorno); }
public static ServiceRota MapToModel(ToggleServiceRota toggleServiceRota) { if (toggleServiceRota == null) { return(new ServiceRota()); } return(new ServiceRota { Id = toggleServiceRota.ServiceRotaId, Authorization = toggleServiceRota.ServiceRota.Authorization, Rota = toggleServiceRota.ServiceRota.Rota, Active = toggleServiceRota.ServiceRota.Active }); }
public async Task <HttpResult <Toggle> > Update(int id, string description, bool flag, List <int> idsServiceRota) { var retorno = new HttpResult <Toggle>(); var retornoToggleGet = await ToggleEntityService.Get(id); if (retornoToggleGet == null) { return(retorno.SetHttpStatusToNotFound()); } retornoToggleGet.Description = description; retornoToggleGet.Flag = flag; if (idsServiceRota != null && idsServiceRota.Count > 0) { retornoToggleGet.ToggleServiceRotas = null; retornoToggleGet.ToggleServiceRotas = new List <ToggleServiceRota>(); } foreach (var idServiceRota in idsServiceRota) { var retornoServiceRotaGet = ServiceRotaEntityService.Get(idServiceRota); if (retornoServiceRotaGet == null) { return(retorno.SetHttpStatusToNotFound()); } var toggleServiceRota = new ToggleServiceRota(); toggleServiceRota.ServiceRota = retornoServiceRotaGet.Result; toggleServiceRota.Toggle = retornoToggleGet; retornoToggleGet.ToggleServiceRotas.Add(toggleServiceRota); } _dbContext.SaveChanges(); retorno.Response = retornoToggleGet; retorno.SetHttpStatusToOk(); return(retorno); }