public IHttpActionResult GetAccessoriesForRestoreItem(Client_ConceptionsAndAccessoryTypes input) { List <Accessory_RestoreItem> result = new List <Accessory_RestoreItem>(); try { foreach (var conceptionPK in input.conceptionPKs) { List <int> tempAccessoriesPK = (from unit in db.ConceptionAccessories where unit.ConceptionPK == conceptionPK select unit.AccessoryPK).ToList(); foreach (var AccessoryPK in tempAccessoriesPK) { Accessory tempAccessory = db.Accessories.Find(AccessoryPK); if (input.accessorytypePKs.Contains(tempAccessory.AccessoryTypePK)) { result.Add(new Accessory_RestoreItem(tempAccessory)); } } } } catch (Exception e) { return(Content(HttpStatusCode.Conflict, new Content_InnerException(e).InnerMessage())); } return(Content(HttpStatusCode.OK, result)); }
public IHttpActionResult GetAccessoriesForFilter(Client_ConceptionsAndAccessoryTypes input, bool onlyNonImagedAccessory, string customerName) { List <Accessory_RestoreItem2> result = new List <Accessory_RestoreItem2>(); try { Customer customer = (from cus in db.Customers where cus.CustomerName == customerName select cus).FirstOrDefault(); if (customer == null) { return(Content(HttpStatusCode.Conflict, "CUSTOMER KHÔNG TỒN TẠI!")); } List <int> tempAccessoriesPK = (from acc in db.Accessories where acc.CustomerPK == customer.CustomerPK select acc.AccessoryPK).ToList(); foreach (var AccessoryPK in tempAccessoriesPK) { if (input.conceptionPKs.Count == 0) { Accessory tempAccessory = db.Accessories.Find(AccessoryPK); if (input.accessorytypePKs.Contains(tempAccessory.AccessoryTypePK)) { if (onlyNonImagedAccessory == true) { if (tempAccessory.Image == null) { tempAccessory.Image = "default.png"; result.Add(new Accessory_RestoreItem2(tempAccessory)); } } else { if (tempAccessory.Image == null) { tempAccessory.Image = "default.png"; } result.Add(new Accessory_RestoreItem2(tempAccessory)); } } } else { foreach (var conceptionPK in input.conceptionPKs) { if ((from unit in db.ConceptionAccessories where unit.ConceptionPK == conceptionPK && unit.AccessoryPK == AccessoryPK select unit).FirstOrDefault() != null) { Accessory tempAccessory = db.Accessories.Find(AccessoryPK); if (input.accessorytypePKs.Contains(tempAccessory.AccessoryTypePK)) { if (onlyNonImagedAccessory == true) { if (tempAccessory.Image == null) { tempAccessory.Image = "default.png"; result.Add(new Accessory_RestoreItem2(tempAccessory)); } } else { if (tempAccessory.Image == null) { tempAccessory.Image = "default.png"; } result.Add(new Accessory_RestoreItem2(tempAccessory)); } } } } } } } catch (Exception e) { return(Content(HttpStatusCode.Conflict, new Content_InnerException(e).InnerMessage())); } return(Content(HttpStatusCode.OK, result)); }