Esempio n. 1
0
        public CourtItem GetCourt(int?courtID = null)
        {
            if (courtID != null)
            {
                var dbItem = (from court in db.Courts
                              join t1 in db.CourtTypes on court.CourtTypeID equals t1.CourtTypeID into r1
                              from courtType in r1.DefaultIfEmpty()
                              where court.CourtID == courtID
                              select new { courtTable = court, courtTypeTable = courtType })
                             .Select(list => new CourtItem
                {
                    CourtID       = list.courtTable.CourtID,
                    CourtName     = list.courtTable.CourtName,
                    CourtTypeID   = list.courtTable.CourtTypeID,
                    CourtTypeName = list.courtTypeTable.CourtTypeName
                }).First();


                CourtItem item = new CourtItem
                {
                    CourtID       = dbItem.CourtID,
                    CourtName     = dbItem.CourtName,
                    CourtTypeID   = dbItem.CourtTypeID,
                    CourtTypeName = dbItem.CourtTypeName
                };
                return(item);
            }
            else
            {
                var item = new CourtItem();
                return(item);
            }
        }
Esempio n. 2
0
        public CourtItem UpdateCourt(CourtItem item)
        {
            Court dbItem = db.Courts.Find(item.CourtID);

            dbItem.CourtID     = (int)item.CourtID;
            dbItem.CourtName   = item.CourtName;
            dbItem.CourtTypeID = item.CourtTypeID;
            db.Courts.Attach(dbItem);
            db.Entry(dbItem).State = EntityState.Modified;
            db.SaveChanges();
            return(item);
        }
Esempio n. 3
0
        public CourtItem InsertCourt(CourtItem item)
        {
            Court dbItem = new Court
            {
                CourtName   = item.CourtName,
                CourtTypeID = item.CourtTypeID
            };

            db.Courts.Add(dbItem);
            db.SaveChanges();
            item.CourtID = dbItem.CourtID;
            return(item);
        }