public static bool AddOrUpdateTerritoryCard(ref TerritoryCardData card)
        {
            if (card.ItemId <= 0)
            {
                return(AddTerritoryCard(ref card));
            }
            try {
                using (var db = new TerritoryCardsDataContext()) {
                    var i = card.ItemId;
                    var c = db.TerritoryCardItems.Single(x => x.ItemId == i);
                    if (c == null)
                    {
                        return(AddTerritoryCard(ref card));
                    }

                    c.ImageSrc        = card.ImageSrc;
                    c.Notes           = card.Notes;
                    c.TerritoryNumber = card.TerritoryNumber;
                    c.DateCreated     = card.DateCreated;

                    db.SubmitChanges();
                    return(true);
                }
            }
            catch (InvalidOperationException) {
                return(AddTerritoryCard(ref card));
            }
            catch (Exception e) {
                throw e;
            }
        }
 internal static TerritoryCardItem Copy(TerritoryCardData card)
 {
     return(new TerritoryCardItem
     {
         ItemId = card.ItemId,
         DateCreated = card.DateCreated,
         ImageSrc = card.ImageSrc,
         Notes = card.Notes,
         TerritoryNumber = card.TerritoryNumber
     });
 }
 private static bool AddTerritoryCard(ref TerritoryCardData card)
 {
     try {
         using (var db = new TerritoryCardsDataContext()) {
             var newCard = TerritoryCardData.Copy(card);
             db.TerritoryCardItems.InsertOnSubmit(newCard);
             db.SubmitChanges();
             card.ItemId = newCard.ItemId;
             return(card.ItemId > 0);
         }
     }
     catch {
         return(false);
     }
 }
        public static TerritoryCardData GetTerritoryCard(int itemId)
        {
            try {
                using (var db = new TerritoryCardsDataContext()) {
                    var c = db.TerritoryCardItems.Single(x => x.ItemId == itemId);
                    if (c == null)
                    {
                        return(null);
                    }

                    return(TerritoryCardData.Copy(c));
                }
            }
            catch (InvalidOperationException e) {
                return(null);
            }
        }
        public static TerritoryCardData[] GetTerritoryCards(SortOrder so)
        {
            try {
                using (var db = new TerritoryCardsDataContext()) {
                    var qry = from x in db.TerritoryCardItems
                              orderby x.DateCreated
                              select x;

                    if (!qry.Any())
                    {
                        return(null);
                    }
                    return(qry.Select(c => TerritoryCardData.Copy(c)).ToArray());
                }
            }
            catch {
                return(null);
            }
        }
 internal static TerritoryCardItem Copy(TerritoryCardData card)
 {
     return new TerritoryCardItem
     {
         ItemId = card.ItemId,
         DateCreated = card.DateCreated,
         ImageSrc = card.ImageSrc,
         Notes = card.Notes,
         TerritoryNumber = card.TerritoryNumber
     };
 }
 private static bool AddTerritoryCard(ref TerritoryCardData card)
 {
     try {
         using (var db = new TerritoryCardsDataContext()) {
             var newCard = TerritoryCardData.Copy(card);
             db.TerritoryCardItems.InsertOnSubmit(newCard);
             db.SubmitChanges();
             card.ItemId = newCard.ItemId;
             return card.ItemId > 0;
         }
     }
     catch {
         return false;
     }
 }
        public static bool AddOrUpdateTerritoryCard(ref TerritoryCardData card)
        {
            if (card.ItemId <= 0) return AddTerritoryCard(ref card);
            try {
                using (var db = new TerritoryCardsDataContext()) {
                    var i = card.ItemId;
                    var c = db.TerritoryCardItems.Single(x => x.ItemId == i);
                    if (c == null) return AddTerritoryCard(ref card);

                    c.ImageSrc = card.ImageSrc;
                    c.Notes = card.Notes;
                    c.TerritoryNumber = card.TerritoryNumber;
                    c.DateCreated = card.DateCreated;

                    db.SubmitChanges();
                    return true;
                }
            }
            catch (InvalidOperationException) {
                return AddTerritoryCard(ref card);
            }
            catch (Exception e) {
                throw e;
            }
        }
 public EditTerritoryCardViewModel()
 {
         TerritoryCard = new TerritoryCardData();
 }