public JsonResult Create(AireModel model) { try { var dbitem = new Aire { Description = model.Description, CoupeId = model.CoupeId, NetClientId = model.NetClientId }; this.repository.Create(dbitem); try { var clients = this.unitOfWork.Repository <NetClient>(); var client = clients.Read(model.NetClientId); client.AireId = dbitem.Id; clients.Update(client); } catch (Exception) { throw; } return(Json(dbitem.ToModel())); } catch { throw; } }
public JsonResult Delete(AireModel model) { try { var dbmodel = this.repository.Read(m => m.Id == model.Id).First(); if (dbmodel != null) { this.repository.Delete(dbmodel); try { var clients = this.unitOfWork.Repository <NetClient>(); var client = clients.Read(model.NetClientId); client.AireId = 0; clients.Update(client); } catch (Exception) { throw; } return(Json(model)); } else { throw new ArgumentException("L'aire est absente de la base de données", "model"); } } catch { throw; } }
public static AireModel ToModel(this Aire dto) { AireModel result = new AireModel(); result.Id = dto.Id; result.CoupeId = dto.CoupeId; result.Description = dto.Description; result.NetClientId = dto.NetClientId; if (dto.Epreuves != null && dto.Epreuves.Count() > 0) { result.EpreuveId = dto.Epreuves.FirstOrDefault().Id.ToString(); } else { result.EpreuveId = string.Empty; } return(result); }
public JsonResult Update(AireModel model) { try { var dbmodel = this.repository.Read(m => m.Id == model.Id).First(); if (dbmodel != null) { dbmodel.Description = model.Description; dbmodel.CoupeId = model.CoupeId; dbmodel.NetClientId = model.NetClientId; this.repository.Update(dbmodel); return(Json(model)); } else { throw new ArgumentException("L'aire est absente de la base de données", "model"); } } catch { throw; } }