/// <summary>
        /// Try & see if we can find a record in the DB based off the User ID
        /// </summary>
        /// <param name="identityId">The user or member ID to try and find in the DB</param>
        /// <returns>Returns Auth Token record/object in DB or null if not found</returns>
        public static UmbracoAuthToken GetAuthToken(int identityId)
        {
            //Try & find a record in the DB from the userId
            var findRecord = Database.SingleOrDefault <UmbracoAuthToken>("WHERE IdentityId=@0", identityId);

            //Return the object (Will be null if can't find an item)
            return(findRecord);
        }
Ejemplo n.º 2
0
        public StructuralGroup GetById(int id)
        {
            if (_allGroupCache != null)
            {
                return(_allGroupCache.SingleOrDefault(g => g.Id == id));
            }

            return(_db.SingleOrDefault <StructuralGroup>(id));
        }
Ejemplo n.º 3
0
        private RestaurantPoco GetRestaurantPoco(int id)
        {
            var restaurant = _db.SingleOrDefault <RestaurantPoco>("SELECT * FROM Restaurants WHERE Id = @0", id);

            if (restaurant == null)
            {
                throw new KeyNotFoundException(string.Format("Restaurant {0} not found in database", id));
            }
            return(restaurant);
        }
Ejemplo n.º 4
0
        public JsonResult <Season> GetById(int id = 1)
        {
            UmbracoDatabase db = ApplicationContext.DatabaseContext.Database;
            //var result = db.SingleOrDefault<Season>(string.Format("SELECT * FROM Seasons WHERE Season_Id = {0}", id));
            //or
            var result = db.SingleOrDefault <Season>(new Sql()
                                                     .Select("*")
                                                     .From("Seasons")
                                                     .Where(string.Format("Season_Id = {0}", id)));

            return(Json(result));
        }
Ejemplo n.º 5
0
        public async Task <HttpResponseMessage> Upload()
        {
            if (!this.Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            UmbracoDatabase db       = ApplicationContext.DatabaseContext.Database;
            var             provider = new MultipartFormDataStreamProvider(Path.GetTempPath());
            await Request.Content.ReadAsMultipartAsync(provider);

            var file = provider.FileData.Count > 0 ? provider.FileData.First() : null;

            // check if any file is uploaded
            if (file == null)
            {
                return(this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "No file uploaded"));
            }

            string fileName      = file.Headers.ContentDisposition.FileName.Trim('"');
            string fileExtension = fileName.Substring(fileName.LastIndexOf('.') + 1);

            // check if the file of the required type
            if (fileExtension != "csv")
            {
                return(this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Required format *.csv"));
            }

            string gameId = provider.FormData.GetValues("gameId").First();
            var    game   = new Game();

            // check if game is selected
            if (gameId != "undefined")
            {
                // get game instance for uploaded file
                game = db.SingleOrDefault <Game>(new Sql()
                                                 .Select("*")
                                                 .From("Games")
                                                 .Where(string.Format("Game_Id = {0}", Int32.Parse(gameId))));
            }
            else
            {
                return(this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "No game selected"));
            }

            // get all stat types to parse file
            var statTypes = db.Fetch <StatType>(new Sql()
                                                .Select("*")
                                                .From("StatTypes"));


            string[] csvFileContent = File.ReadAllLines(file.LocalFileName);
            foreach (string line in csvFileContent.Skip(1))
            {
                if (!line.IsNullOrWhiteSpace())
                {
                    string[] words      = line.Split(','); // contains period, time, descr, playerid
                    int      statTypeId = 0;
                    foreach (var statType in statTypes)
                    {
                        // parse *description* from CSV to match it with StatType
                        if (words[2].Contains(statType.Stat_Type_Keyphrase))
                        {
                            statTypeId = statType.Stat_Type_Id;
                            break;
                        }
                    }

                    var stat = new Stat
                    {
                        Game_Id   = game.Game_Id,
                        Period    = Int32.Parse(words[0]),
                        Stat_Time = new DateTime(game.Game_Date.Year, game.Game_Date.Month, game.Game_Date.Day,
                                                 Int32.Parse(words[1].Substring(0, words[1].LastIndexOf(':'))),
                                                 Int32.Parse(words[1].Substring(words[1].LastIndexOf(':') + 1)), 0),
                        Stat_Type_Id = statTypeId,
                        Player_Id    = Int32.Parse(words[3])
                    };
                    db.Insert(stat);
                }
            }

            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
Ejemplo n.º 6
0
 public Product GetById(int productId)
 {
     return(db.SingleOrDefault <Product>(productId));
 }
Ejemplo n.º 7
0
 public Order GetById(int orderId)
 {
     return(db.SingleOrDefault <Order>(orderId));
 }
Ejemplo n.º 8
0
 public Category GetById(int categoryId)
 {
     return(db.SingleOrDefault <Category>(categoryId));
 }
 public Person GetById(int personId)
 {
     return(_database.SingleOrDefault <Person>(personId));
 }