public static CollectionPointModel GetCollectionPointByCpid(int cpid, out string error) { LUSSISEntities entities = new LUSSISEntities(); error = ""; collectionpoint cp = new collectionpoint(); CollectionPointModel cpm = new CollectionPointModel(); try { cp = entities.collectionpoints.Where(p => p.cpid == cpid).FirstOrDefault <collectionpoint>(); cpm = CovertDBCptoAPICp(cp); } catch (NullReferenceException) { error = ConError.Status.NOTFOUND; } catch (Exception e) { error = e.Message; } return(cpm); }
public static CollectionPointModel CreateCollectionPoint(CollectionPointModel cpm, out string error) { error = ""; LUSSISEntities entities = new LUSSISEntities(); collectionpoint cp = new collectionpoint(); try { cp.cpname = cpm.Cpname; cp.cplocation = cpm.Cplocation; cp.latitude = cpm.Latitude; cpm.Longitude = cpm.Longitude; cp = entities.collectionpoints.Add(cp); entities.SaveChanges(); cpm = GetCollectionPointByCpid(cp.cpid, out error); } catch (NullReferenceException) { error = ConError.Status.NOTFOUND; } catch (Exception e) { error = e.Message; } return(cpm); }
public static CollectionPointModel UpdateCollectionPoint(CollectionPointModel cpm, out string error) { error = ""; // declare and initialize new LUSSISEntities to perform update LUSSISEntities entities = new LUSSISEntities(); collectionpoint cp = new collectionpoint(); try { // finding the collectionpoint object using CollectionPoint API model cp = entities.collectionpoints.Where(p => p.cpid == cpm.Cpid).First <collectionpoint>(); // transfering data from API model to DB Model cp.cpname = cpm.Cpname; cp.cplocation = cpm.Cplocation; cp.latitude = cpm.Latitude; cpm.Longitude = cpm.Longitude; // saving the update entities.SaveChanges(); // return the updated model cpm = CovertDBCptoAPICp(cp); } catch (NullReferenceException) { error = ConError.Status.NOTFOUND; } catch (Exception e) { error = e.Message; } return(cpm); }
// Convert From Auto Generated DB Model to APIModel private static CollectionPointModel CovertDBCptoAPICp(collectionpoint cp) { CollectionPointModel cpm = new CollectionPointModel(cp.cpid, cp.cpname, cp.cplocation, cp.latitude, cp.longitude); return(cpm); }