// GET: api/TypeOfEquipmentMalfunction/5 public TypeOfEquipmentMalfunctionModel Get(int id) { TypeOfEquipmentMalfunctionModel typeOfEquipmentMalfunction = new TypeOfEquipmentMalfunctionModel(); //t_Malfunction malfunction; // = new malfunction(); t_TypeOfEquipment typeOfEquipment = db.t_TypeOfEquipment.Where(w => w.TypeId == id).FirstOrDefault(); #if DEBUG Debug.WriteLine("typeOfEquipment.Name=" + typeOfEquipment.Name + " typeOfEquipment.TypeId=" + typeOfEquipment.TypeId.ToString()); #endif //typeOfEquipmentMalfunction.Malfunctions= (malfunction.t_TypeOfEquipment.Where(s => s.TypeId == id)).ToList(); //typeOfEquipmentMalfunction.selectedMalfunctions = (typeOfEquipment.ref_Malfunction).ToList(); IList <int> typeOfEquipments = (typeOfEquipment.t_Malfunction.Join(db.t_Malfunction, sw => sw.FaultId, s => s.FaultId, (sw, s) => s.FaultId).ToList()); #if DEBUG Debug.WriteLine("typeOfEquipments.count=" + typeOfEquipments.Count.ToString()); #endif //typeOfEquipmentMalfunction.selectedMalfunctions = db.t_Malfunction.Where(w => typeOfEquipments.Contains(w.FaultId)).Select(s=>new t_Malfunction{FaultId=s.FaultId,Name=s.Name}).ToList(); typeOfEquipmentMalfunction.selectedMalfunctions = (from m in db.t_Malfunction where typeOfEquipments.Contains(m.FaultId) select(new MalfunctionModel() { FaultId = m.FaultId, Name = m.Name })).ToList(); //typeOfEquipments.Contains(1) typeOfEquipmentMalfunction.Malfunctions = db.t_Malfunction.Select(s => new MalfunctionModel() { FaultId = s.FaultId, Name = s.Name }).ToList(); typeOfEquipmentMalfunction.TypeId = id; //typeOfEquipmentMalfunction.Malfunctions = db.t_TypeOfEquipment; #if DEBUG Debug.WriteLine("Начало выбора Malfunction"); foreach (MalfunctionModel item in typeOfEquipmentMalfunction.selectedMalfunctions) { Debug.WriteLine("FaultId={0},Name={1}", item.FaultId.ToString(), item.Name); } #endif return(typeOfEquipmentMalfunction); }
public IQueryable <TypeofEquipmentModel> Postt_TypeOfEquipment(t_TypeOfEquipment t_TypeOfEquipment) //public IHttpActionResult Postt_TypeOfEquipment(t_TypeOfEquipment t_TypeOfEquipment) { if (!ModelState.IsValid) { #if DEBUG Debug.WriteLine("Model is NOT valid!"); #endif //return BadRequest(ModelState); return(db.t_TypeOfEquipment.Select(s => new TypeofEquipmentModel() { TypeId = s.TypeId, Name = s.Name, Effective = s.Effective, Warranty = s.Warranty, Limit = s.Limit }).AsQueryable()); } #if DEBUG Debug.WriteLine("t_TypeOfEquipment.Name=" + t_TypeOfEquipment.Name.ToString()); #endif db.t_TypeOfEquipment.Add(t_TypeOfEquipment); db.SaveChanges(); return(db.t_TypeOfEquipment.Select(s => new TypeofEquipmentModel() { TypeId = s.TypeId, Name = s.Name, Effective = s.Effective, Warranty = s.Warranty, Limit = s.Limit }).AsQueryable()); //return CreatedAtRoute("DefaultApi", new { id = t_TypeOfEquipment.TypeId }, t_TypeOfEquipment); }
//public IHttpActionResult Putt_TypeOfEquipment(int id, t_TypeOfEquipment t_TypeOfEquipment) public IQueryable <TypeofEquipmentModel> Putt_TypeOfEquipment(int id, TypeofEquipmentModel typeOfEquipmentModel) { if (!ModelState.IsValid) { //return BadRequest(ModelState); return(db.t_TypeOfEquipment.Select(s => new TypeofEquipmentModel() { TypeId = s.TypeId, Name = s.Name, Effective = s.Effective, Warranty = s.Warranty, Limit = s.Limit }).AsQueryable()); } t_TypeOfEquipment typeOfEquipment = db.t_TypeOfEquipment.Find(id); if (typeOfEquipment == null) { //return BadRequest(); return(db.t_TypeOfEquipment.Select(s => new TypeofEquipmentModel() { TypeId = s.TypeId, Name = s.Name, Effective = s.Effective, Warranty = s.Warranty, Limit = s.Limit }).AsQueryable()); } typeOfEquipment.Name = typeOfEquipmentModel.Name; typeOfEquipment.Warranty = typeOfEquipmentModel.Warranty; typeOfEquipment.Limit = typeOfEquipmentModel.Limit; typeOfEquipment.Effective = typeOfEquipmentModel.Effective; try { db.Entry(typeOfEquipment).State = EntityState.Modified; db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!t_TypeOfEquipmentExists(id)) { //return NotFound(); return(db.t_TypeOfEquipment.Select(s => new TypeofEquipmentModel() { TypeId = s.TypeId, Name = s.Name, Effective = s.Effective, Warranty = s.Warranty, Limit = s.Limit }).AsQueryable()); } else { throw; } } return(db.t_TypeOfEquipment.Select(s => new TypeofEquipmentModel() { TypeId = s.TypeId, Name = s.Name, Effective = s.Effective, Warranty = s.Warranty, Limit = s.Limit }).AsQueryable()); //return StatusCode(HttpStatusCode.NoContent); }
public void Put(int id, int typeId) { t_Equipment equipment = db.t_Equipment.Find(id); var selectedEquipments = equipment.t_TypeOfEquipment.ToList(); if (selectedEquipments != null) { foreach (t_TypeOfEquipment selectedEquipment in selectedEquipments) { equipment.t_TypeOfEquipment.Remove(selectedEquipment); db.SaveChanges(); } } t_TypeOfEquipment typeOfEquipment = db.t_TypeOfEquipment.Find(typeId); if (typeOfEquipment != null) { equipment.t_TypeOfEquipment.Add(typeOfEquipment); db.SaveChanges(); } }
public IQueryable <TypeofEquipmentModel> Deletet_TypeOfEquipment(int id) { t_TypeOfEquipment t_TypeOfEquipment = db.t_TypeOfEquipment.Find(id); if (t_TypeOfEquipment == null) { //return NotFound(); return(db.t_TypeOfEquipment.Select(s => new TypeofEquipmentModel() { TypeId = s.TypeId, Name = s.Name, Effective = s.Effective, Warranty = s.Warranty, Limit = s.Limit }).AsQueryable()); } db.t_TypeOfEquipment.Remove(t_TypeOfEquipment); db.SaveChanges(); //return Ok(t_TypeOfEquipment); return(db.t_TypeOfEquipment.Select(s => new TypeofEquipmentModel() { TypeId = s.TypeId, Name = s.Name, Effective = s.Effective, Warranty = s.Warranty, Limit = s.Limit }).AsQueryable()); }
public TypeOfEquipmentMalfunctionOps(int TypeID) { db = new TExpEntities(); typeOfEquipment = db.t_TypeOfEquipment.Find(TypeID); }