internal static CoriaMapBook CreateUpdateMapBook(CoriaMapBook coriaMapBook) { if (coriaMapBook.Id == 0) { coriaMapBook = CreateNewMapBookApplication(coriaMapBook); } else { Func <CoriaMapBook, MapBook> toMapBook = (CoriaMapBook fromCoriaMapBook) => ToMapBook(fromCoriaMapBook, new MapBook()); Func <MapBook, CoriaMapBook> toCoriaMapBook = (MapBook fromMapBook) => ToCoriaMapBook(fromMapBook, new CoriaMapBook()); using (KhartaDataModel dbcontext = new KhartaDataModel()) { try { dbcontext.Entry(toMapBook(coriaMapBook)).State = System.Data.Entity.EntityState.Modified; dbcontext.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { //TODO: handle exception and log it var exception = ex; } } coriaMapBook = GetCoriaMapBookApplication(coriaMapBook.Id); } return(coriaMapBook); }
internal static void DeleteCoriaMapBookApplication(CoriaMapBook coriamapbook) { using (KhartaDataModel dbcontext = new KhartaDataModel()) { var result = (from m in dbcontext.MapBooks where m.ApplicationId.Equals(coriamapbook.ApplicationId) select m).FirstOrDefault(); MapBook mapbook = result; dbcontext.MapBooks.Remove(mapbook); dbcontext.SaveChanges(); } }
internal static CoriaMapBook CreateNewMapBookApplication(CoriaMapBook coriaMapBook) { Func <CoriaMapBook, MapBook> toMapBook = (CoriaMapBook fromCoriaMapBook) => ToMapBook(fromCoriaMapBook, new MapBook()); Func <MapBook, CoriaMapBook> toCoriaMapBook = (MapBook fromMapBook) => ToCoriaMapBook(fromMapBook, new CoriaMapBook()); try { using (KhartaDataModel dbcontext = new KhartaDataModel()) { MapBook mapbook = dbcontext.MapBooks.Add(toMapBook(coriaMapBook)); dbcontext.SaveChanges(); return(toCoriaMapBook(mapbook)); } } catch (Exception ex) { //TODO: log exception var exception = ex; throw; } }
internal static MapBook ToMapBook(CoriaMapBook fromCoriaMapBook, MapBook toMapBook) { return((MapBook)ConvertFromPropertiesTo(fromCoriaMapBook, toMapBook)); }
internal static CoriaMapBook ToCoriaMapBook(MapBook fromMapBook, CoriaMapBook toCoriaMapBook) { return((CoriaMapBook)ConvertFromPropertiesTo(fromMapBook, toCoriaMapBook)); }