Beispiel #1
0
        public HttpResponseMessage Post(Oceny ocena)
        {
            this.ocenaRepository.SaveOcena(ocena);

            var response = Request.CreateResponse<Oceny>(System.Net.HttpStatusCode.Created, ocena);

            return response;
        }
Beispiel #2
0
        public OcenyRepository()
        {
            var ctx = HttpContext.Current;

            if (ctx != null)
            {
                if (ctx.Cache[CacheKey] == null)
                {
                    var oceny = new Oceny[]
                    {
                        new Oceny { Id = 1, Nazwisko = "Boszke", Ocena = 5 },
                        new Oceny { Id = 2, Nazwisko = "Adamiakowa", Ocena = 3.5F },
                        new Oceny { Id = 3, Nazwisko = "Kowalski",  Ocena = 2 }
                    };

                    ctx.Cache[CacheKey] = oceny;
                }
            }
        }
Beispiel #3
0
        public bool SaveOcena(Oceny ocena)
        {
            var ctx = HttpContext.Current;

            if (ctx != null)
            {
                try
                {
                    var currentData = ((Oceny[])ctx.Cache[CacheKey]).ToList();
                    currentData.Add(ocena);
                    ctx.Cache[CacheKey] = currentData.ToArray();

                    return true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    return false;
                }
            }

            return false;
        }