Beispiel #1
0
 public ActionResult Edit([Bind(Include = "ID,number,state,expirationDate")] Card card)
 {
     if (ModelState.IsValid)
     {
         db.Entry(card).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(card));
 }
Beispiel #2
0
        //
        // GET: /Cards/Archive/5

        public ActionResult Archive(string cid = null, string bid = null)
        {
            Card card = db.Cards.Find(cid, bid);

            if (card == null)
            {
                return(HttpNotFound());
            }
            card.archived        = true;
            db.Entry(card).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public static bool UpdateData(CardContext db, List <ForecastCard> forecastCards)
 {
     foreach (var card in forecastCards)
     {
         if (DataValidation.AllValidation(card))
         {
             ForecastCard forecastCard = db.ForecastCards.FirstOrDefault(x => x.DateTime == card.DateTime);
             if (forecastCard == null)
             {
                 db.ForecastCards.Add(card);
             }
             else
             {
                 forecastCard.Description     = card.Description;
                 forecastCard.Humidity        = card.Humidity;
                 forecastCard.Temperature     = card.Temperature;
                 forecastCard.WindDirection   = card.WindDirection;
                 db.Entry(forecastCard).State = EntityState.Modified;
             }
         }
     }
     try
     {
         db.SaveChanges();
         return(true);
     }
     catch (Exception ex) {
         return(false);
     };
 }
Beispiel #4
0
        public IHttpActionResult PutCard(int id, Card card)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CardExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IActionResult> Edit(Guid id, [Bind("Id,Number,PIN,AvailableMoney,Status")] Card card)
        {
            if (id != card.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    //_context.Update(card);
                    _context.Entry(card).State = EntityState.Modified;
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CardExists(card.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(card));
        }
        public async Task <IActionResult> PutCard([FromRoute] string id, [FromBody] Card card)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != card.Id)
            {
                return(BadRequest());
            }

            _context.Entry(card).State = EntityState.Modified;

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

            return(NoContent());
        }
Beispiel #7
0
 public void Update(Model.Match M, string current)
 {
     if (M.Guess != current)
     {
         M.Guess = current;
         using (var context = new CardContext())
         {
             context.Entry(M).State = System.Data.Entity.EntityState.Modified;
             context.SaveChanges();
         }
     }
 }
Beispiel #8
0
        private static void SaveImageUris(CardContext context, List <ImageUri> storedUris, List <ImageUri> incomingUris)
        {
            var itemsToAdd    = incomingUris.ToArray().Where(d => !storedUris.Any(c => c.Id == d.Id));
            var itemsToUpdate = storedUris.Where(d => incomingUris.ToArray().Any(c => c.Id == d.Id));
            var itemsToRemove = storedUris.Where(d => !incomingUris.ToArray().Any(c => c.Id == d.Id));

            foreach (var update in itemsToUpdate)
            {
                context.Entry(update).CurrentValues.SetValues(incomingUris.ToArray().Where(d => d.Id == update.Id).SingleOrDefault());
            }
            context.ImageUris.RemoveRange(itemsToRemove);
            context.ImageUris.AddRange(itemsToAdd);
        }