Exemple #1
0
        public async Task <IHttpActionResult> PutSnus(int id, Snus snus)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != snus.SnusId)
            {
                return(BadRequest());
            }

            db.Entry(snus).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SnusExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var dB       = new SnusbrotherDataContext();
            var profile1 = new Profile
            {
                Name     = "Sivert",
                Username = "******",
                Password = "******"
            };

            var snus1 = new Snus
            {
                Name    = "g3",
                Price   = 50.0,
                Profile = profile1
            };

            var snus2 = new Snus
            {
                Name    = "06",
                Price   = 40.0,
                Profile = profile1
            };

            dB.Snus.Add(snus1);
            dB.Snus.Add(snus2);

            dB.SaveChanges();
            Console.Out.WriteLine("Finished");
        }
Exemple #3
0
        public async Task <IHttpActionResult> GetSnus(int id)
        {
            Snus snus = await db.Snus.FindAsync(id);

            if (snus == null)
            {
                return(NotFound());
            }

            return(Ok(snus));
        }
Exemple #4
0
        public async Task <IHttpActionResult> PostSnus(Snus snus)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Snus.Add(snus);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = snus.SnusId }, snus));
        }
Exemple #5
0
        public async Task <IHttpActionResult> DeleteSnus(int id)
        {
            Snus snus = await db.Snus.FindAsync(id);

            if (snus == null)
            {
                return(NotFound());
            }

            db.Snus.Remove(snus);
            await db.SaveChangesAsync();

            return(Ok(snus));
        }
 private async void AddSnusToStash()
 {
     ErrorMessage = "";
     if (Name != "")
     {
         var snus = new Snus
         {
             Name         = Name,
             Price        = Price,
             SnusStrength = Strength,
             ProfileId    = ProfileHandler.CurrentProfile.ProfileId
         };
         if (await DataTransferUtility.PostSnus(snus) == true)
         {
             MyStashList.Add(snus);
         }
         ErrorMessage = "Snus added to stash";
     }
     else
     {
         ErrorMessage = "The Name field has to be filled";
     }
 }