Beispiel #1
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));
        }
Beispiel #2
0
        public int AddCard(Card card)
        {
            if (card == null)
            {
                throw new Exception("AddCard method error: Card is null");
            }


            var todolist = new Todolist
            {
                Title   = "Todolist",
                TodoIds = ""
            };

            _todolistContext.Todolists.Add(todolist);
            _todolistContext.SaveChanges();

            card.TodolistId = todolist.Id;
            _db.Cards.Add(card);
            _db.SaveChanges();

            var board = _dbBoard.Boards.Find(card.BoardId);

            board.AddCardId(card.Id);
            _dbBoard.Boards.Update(board);
            _dbBoard.SaveChanges();

            var column = _dbColumn.Columns.Find(card.ColumnId);

            column.AddCardId(card.Id);
            _dbColumn.Columns.Update(column);
            _dbColumn.SaveChanges();

            return(card.Id);
        }
        private void AttackEditor_CreateAttack_Button_Click(object sender, RoutedEventArgs e)
        {
            if (!CheckValidInput())
            {
                MessageBox.Show("Some values are not valid!", "Invalid Input!");
                return;
            }

            using (CardContext context = new CardContext())
            {
                if (editAttack)
                {
                    Attack updatedAttack = context.Attacks.Find(currentAttack.ID);

                    updatedAttack.Name       = AttackEditor_Name_Textbox.Text;
                    updatedAttack.CardTypeID = ((CardType)AttackEditor_Type_Combobox.SelectedItem).ID;
                    updatedAttack.Damage     = int.Parse(AttackEditor_Damage_Textbox.Text);

                    context.SaveChanges();
                }
                else
                {
                    Attack newAttack = new Attack()
                    {
                        Name       = AttackEditor_Name_Textbox.Text,
                        CardTypeID = ((CardType)AttackEditor_Type_Combobox.SelectedItem).ID,
                        Damage     = int.Parse(AttackEditor_Damage_Textbox.Text)
                    };

                    context.Attacks.Add(newAttack);
                    context.SaveChanges();
                }
            }
            Close();
        }
Beispiel #4
0
        public IActionResult Put(int id, [FromBody] Card card)
        {
            if (id != card.id)
            {
                return(BadRequest("Id's nao coincidem"));
            }

            _context.Update(card);
            _context.SaveChanges();

            return(Ok(card));
        }
 private void MainWindow_Delete_Button_Click(object sender, RoutedEventArgs e)
 {
     using (CardContext context = new CardContext())
     {
         foreach (Card c in MainWindow_Cards_ListView.SelectedItems)
         {
             context.Cards.Remove(context.Cards.Find(c.ID));
         }
         context.SaveChanges(); context.SaveChanges();
     }
     RefreshListView();
 }
        public async Task <Card> AddProductToCardAsync(Guid customerID, Guid productID, int quantity)
        {
            using (var db = new CardContext())
            {
                var card = db.Cards
                           .Where(c => c.IsActive == true && c.CustomerID == customerID)
                           .Include(m => m.CardItems)
                           .Include(m => m.CardItems)
                           .FirstOrDefault();

                if (card != null)
                {
                    if (card.CardItems.Any(ci => ci.ProductID != productID))
                    {
                        card.CardItems.Add(new CardItem(customerID, productID, quantity));
                    }
                    else
                    {
                        card.CardItems.Where(ci => ci.ProductID == productID).FirstOrDefault().Quantity += quantity;
                    }
                }
                else
                {
                    db.Add(new Card(customerID, new List <CardItem>()
                    {
                        new CardItem(customerID, productID, quantity)
                    }, true));
                }

                db.SaveChanges();

                return(db.Cards.Where(c => c.CustomerID == customerID && c.IsActive).FirstOrDefault());
            }
        }
        private void TypeEditor_Delete_Button_Click(object sender, RoutedEventArgs e)
        {
            ConfirmDelete confirmDelete = new ConfirmDelete(currentType.Name);

            confirmDelete.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            bool?confirmedDelete = confirmDelete.ShowDialog();

            if (confirmedDelete == false)
            {
                return;
            }


            using (CardContext context = new CardContext())
            {
                foreach (Attack attack in attacks)
                {
                    if (attack.CardTypeID == currentType.ID)
                    {
                        context.Attacks.Remove(attack);
                    }
                }

                context.CardTypes.Remove(context.CardTypes.Find(currentType.ID));
                context.SaveChanges();
            }
            Close();
        }
        private void MainWindow_ImportFromJSON(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openJSON = new OpenFileDialog
            {
                Filter = "Json files (*.json)|*.json"
            };

            openJSON.CheckFileExists = true;

            if (openJSON.ShowDialog() == true)
            {
                if (openJSON.FileName.Trim() != string.Empty)
                {
                    using (StreamReader sr = new StreamReader(openJSON.FileName))
                    {
                        string json = sr.ReadToEnd();

                        List <Card> importedCards = JsonConvert.DeserializeObject <List <Card> >(json);

                        using (CardContext context = new CardContext())
                        {
                            foreach (Card newCard in importedCards)
                            {
                                newCard.ID = 0;
                                context.Cards.Add(newCard);
                                context.SaveChanges();
                            }
                        }
                    }
                    RefreshListView();
                }
            }
        }
 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 #10
0
        public async Task <DbCard> CardAddAsync(DbCard card)
        {
            DbCard addedCard = new DbCard();

            if (card != null)
            {
                try
                {
                    addedCard = (await _context.Cards.AddAsync(card).ConfigureAwait(false)).Entity;
                    _context.SaveChanges();
                }
                catch
                {
                    throw;
                }
            }
            return(addedCard);
        }
 private void AttackEditor_Delete_Button_Click(object sender, RoutedEventArgs e)
 {
     using (CardContext context = new CardContext())
     {
         context.Attacks.Remove(context.Attacks.Find(currentAttack.ID));
         context.SaveChanges();
     }
     Close();
 }
        private void TypeEditor_CreateType_Button_Click(object sender, RoutedEventArgs e)
        {
            if (!CheckValidInput())
            {
                MessageBox.Show("Some values are not valid!", "Invalid Input!");
                return;
            }

            using (CardContext context = new CardContext())
            {
                if (editType)
                {
                    CardType updatedType = context.CardTypes.Find(currentType.ID);

                    updatedType.Name         = TypeEditor_Name_Textbox.Text;
                    updatedType.Cardcolor    = (TypeEditor_Color_Combobox.SelectedItem as PropertyInfo).Name;
                    updatedType.MinHP        = int.Parse(TypeEditor_MinHP_Textbox.Text);
                    updatedType.MaxHP        = int.Parse(TypeEditor_Max_HP_textbox.Text);
                    updatedType.MinAttackDMG = int.Parse(TypeEditor_MinAttackDMG_Textbox.Text);
                    updatedType.MaxAttackDMG = int.Parse(TypeEditor_MaxAttackDMG_Textbox.Text);

                    context.SaveChanges();
                }
                else
                {
                    CardType newType = new CardType()
                    {
                        Name         = TypeEditor_Name_Textbox.Text,
                        Cardcolor    = (TypeEditor_Color_Combobox.SelectedItem as PropertyInfo).Name,
                        MinHP        = int.Parse(TypeEditor_MinHP_Textbox.Text),
                        MaxHP        = int.Parse(TypeEditor_Max_HP_textbox.Text),
                        MinAttackDMG = int.Parse(TypeEditor_MinAttackDMG_Textbox.Text),
                        MaxAttackDMG = int.Parse(TypeEditor_MaxAttackDMG_Textbox.Text)
                    };

                    context.CardTypes.Add(newType);
                    context.SaveChanges();
                }
            }
            Close();
        }
Beispiel #13
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 #14
0
        private async Task <Boolean> SaveCards(object sender, ReceiveEventArgs <SaveCardsRequest> e)
        {
            var storedCards = await Task.FromResult(_context.Cards.ToList());

            var storedUris = await Task.FromResult(_context.ImageUris.ToList());

            var incomingCards = MergeDuplicates(e.Message.CardData.ToList());
            var incomingUris  = e.Message.CardData.Select(i => i.ImageUris).Where(u => u.Small != "").ToList();

            SaveCardDetails(_context, storedCards, incomingCards);
            SaveImageUris(_context, storedUris, incomingUris);
            _context.SaveChanges();
            return(true);
        }
        public ActionResult Post([FromBody] Artist artist)
        {
            var found = _context.Artists.Find(artist.Id);

            if (found != null)
            {
                return(BadRequest("Card already exists!"));
            }
            else
            {
                _context.Artists.Add(artist);
                _context.SaveChanges();
            }
            return(Ok("Card added!"));
        }
Beispiel #16
0
 public ActionResult MeteoData(string data)
 {
     //string data = "r:533|t:15.09|h:84.17|pt:19.43|p:983.65|g:10.60=r:470|t:15.08|h:84.22|pt:19.41|p:983.53|g:6.62=r:477|t:15.11|h:84.61|pt:19.41|p:983.61|g:21.19=";
     if (data != null)
     {
         HistoryCard historyCard = ParserMeteoData.ParseInCard(data);
         historyCard.DateTime = DateTime.Now;
         if (DataValidation.AllValidation(historyCard))
         {
             db.HistoryCards.Add(historyCard);
             db.SaveChanges();
         }
     }
     return(RedirectToAction("OpenWeatherData"));
 }
Beispiel #17
0
 public CardsController(CardContext context)
 {
     db = context;
     if (!db.Cards.Any())
     {
         db.Cards.Add(new Card {
             Owner = "Tom", Number = "5211 4589 6322 0047",
             Term  = "05/23", CVV = "123"
         });
         db.Cards.Add(new Card {
             Owner = "Alice", Number = "5322 1549 3221 4323",
             Term  = "03/22", CVV = "182"
         });
         db.SaveChanges();
     }
 }
        public int AddCardAction(CardAction cardAction)
        {
            if (cardAction == null)
            {
                throw new Exception("AddCardAction method error: cardAction is null");
            }
            _db.CardActions.Add(cardAction);
            _db.SaveChanges();

            var card = _dbCards.Cards.Find(cardAction.CardId);

            card.AddActionId(cardAction.Id);
            _dbCards.Cards.Update(card);
            _dbCards.SaveChanges();
            return(cardAction.Id);
        }
 public int AddComment(Comment comment)
 {
     if (comment == null)
     {
         throw new Exception("AddComment method error: comment is null");
     }
     _db.Comments.Add(comment);
     _db.SaveChanges();
     if (comment.CardId != null)
     {
         var card = _dbCards.Cards.Find(comment.CardId);
         card.AddCommentId(comment.Id);
         _dbCards.Update(card);
         _dbCards.SaveChanges();
     }
     return(comment.Id);
 }
Beispiel #20
0
        public ActionResult Post([FromBody] Card card)
        {
            var id    = (card.SetCode + card.CollectionNumber).ToUpper();
            var found = _context.Cards.SingleOrDefault(c =>
                                                       (c.SetCode + c.CollectionNumber).ToUpper() == id
                                                       );

            if (found != null)
            {
                return(BadRequest("Card already exists!"));
            }
            else
            {
                _context.Cards.Add(card);
                _context.SaveChanges();
            }
            return(Ok("Card added!"));
        }
Beispiel #21
0
        private CardContext GetContextWithData()
        {
            var options = new DbContextOptionsBuilder <CardContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            var dbContext = new CardContext(options);

            dbContext.Cards.Add(new Card {
                Id = 1, Name = "Test Card"
            });
            dbContext.Cards.Add(new Card {
                Id = 2, Name = "Another test Card, this is"
            });
            dbContext.SaveChanges();

            return(dbContext);
        }
Beispiel #22
0
        public ActionResult Block(int?id)
        {
            Card        card        = db.Cards.Find(id);
            CardHistory cardHistory = new CardHistory();

            cardHistory.acquisitionDate = DateTime.Now;
            cardHistory.stateChangeDate = DateTime.Now;
            cardHistory.card            = card;
            if (card == null)
            {
                return(RedirectToAction("Error"));
            }
            if (card.state == State.Registered || card.state == State.Active)
            {
                switch ((int)card.state)
                {
                case 0:
                    card.state        = State.Blocked;
                    cardHistory.state = State.Blocked;
                    db.CardHistories.Add(cardHistory);
                    db.SaveChanges();
                    break;

                case 1:
                    card.state        = State.Blocked;
                    cardHistory.state = State.Blocked;
                    db.CardHistories.Add(cardHistory);
                    db.SaveChanges();
                    break;

                case 2:
                    break;

                case 3:
                    break;

                default:
                    break;
                }
            }
            else
            {
            }

            return(RedirectToAction("Index"));
        }
        public bool UpdateCardQuantity(CardAmountUpdateDto update)
        {
            if (update == null || update.Id <= 0 || update.Quantity < 0)
            {
                return(false);
            }

            var card = _context.Cards.FirstOrDefault(c => c.Id == update.Id);

            if (card == null)
            {
                return(false);
            }

            card.Quantity = update.Quantity;
            _context.SaveChanges();

            return(true);
        }
Beispiel #24
0
        public async Task Execute(IJobExecutionContext context)
        {
            CardContext db = new CardContext();

            List <Card> cards = db.Set <Card>().Where(card => card.expirationDate <= DateTime.Now && card.state != State.Expired).ToList();

            foreach (Card card in cards)
            {
                CardHistory cardHistory = new CardHistory();

                card.state = State.Expired;

                cardHistory.acquisitionDate = DateTime.Now;
                cardHistory.stateChangeDate = DateTime.Now;
                cardHistory.card            = card;
                db.CardHistories.Add(cardHistory);
            }
            db.SaveChanges();
        }
Beispiel #25
0
        private Users CreateUser(SocketUser sender, CardContext db)
        {
            try
            {
                var u = db.Users.Add(new Users
                {
                    Id   = Guid.NewGuid(),
                    Name = sender.Username
                });

                db.SaveChanges();

                return(u.Entity);
            }
            catch (Exception e)
            {
                Logger.Error(e);
                return(null);
            }
        }
Beispiel #26
0
        public int GiveCard(SocketUser sender, SocketUser user, string reason, Cards card, ulong serverId, SocketCommandContext context)
        {
            try
            {
                using (var db = new CardContext())
                {
                    var giver      = Commands.GetDBUser(sender, db);
                    var degenerate = Commands.GetDBUser(user, db);
                    var givenCard  = db.Cards.AsQueryable().Where(c => c.Id == card.Id).FirstOrDefault();

                    var newCard = new CardGivings
                    {
                        Id           = Guid.NewGuid(),
                        CardId       = givenCard.Id,
                        Card         = givenCard,
                        GiverId      = giver.Id,
                        Giver        = giver,
                        DegenerateId = degenerate.Id,
                        Degenerate   = degenerate,
                        CardReason   = reason,
                        ServerId     = serverId,
                        TimeStamp    = DateTime.Now
                    };

                    db.CardGivings.Add(newCard);

                    db.SaveChanges();

                    return(db.CardGivings.AsQueryable()
                           .Where(c => c.Degenerate.Id == degenerate.Id)
                           .Where(c => c.Card.Id == card.Id)
                           .Where(c => c.ServerId == serverId)
                           .Count());
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
                throw;
            }
        }
Beispiel #27
0
        /// <summary>
        /// Сохранить данные карты в базе данных
        /// </summary>
        private void SaveCard()
        {
            using (CardContext db = new CardContext())
            {
                try
                {
                    card = db.Cards.Find(card.Id) is null?db.Cards.Add(card) : db.Cards.Find(card.Id);

                    card.FIO      = fio.Text;
                    card.Gender   = genderM.IsChecked.Value ? genderM.Content.ToString() : genderW.Content.ToString();
                    card.Birthday = date.SelectedDate.Value.ToString("D");
                    card.Address  = address.Text;
                    card.Phone    = phone.Text;
                    db.SaveChanges();
                    Close();
                }
                catch
                {
                }
            }
        }
Beispiel #28
0
        public ActionResult CheckPINCode(string pinCode)
        {
            currentCard = (Card)Session["currentCard"];
            int wrongPINCodeCount = (int)Session["wrongPINCodeCount"];

            if (currentCard != null)
            {
                if (currentCard.PIN == pinCode)
                {
                    return(View("CardOperations"));
                }
                else
                {
                    wrongPINCodeCount++;

                    if (wrongPINCodeCount < 4)
                    {
                        Session["wrongPINCodeCount"] = wrongPINCodeCount;

                        return(View("PINCode"));
                    }
                    else
                    {
                        database.Cards.Attach(currentCard);
                        currentCard.Status = false;

                        database.SaveChanges();

                        Session["currentCard"] = currentCard;

                        return(View("CardNumber"));
                    }
                }
            }
            else
            {
                ViewBag.ErrorMessage = "Card not found!";
                return(View("Error"));
            }
        }
Beispiel #29
0
        static void Main(string[] args)
        {
            var coll = new ServiceCollection();

            coll.AddLogging(b => b.AddConsole());
            var provider = coll.BuildServiceProvider();
            var opt      = new DbContextOptionsBuilder <CardContext>().UseMySql("server=localhost;port=3306;user=root;password=root;database=cardgame", x => x.ServerVersion("5.5.55-mysql"))
                           .UseLoggerFactory((ILoggerFactory)provider.GetService(typeof(ILoggerFactory)));
            var p    = new CardContext(opt.Options);
            var card = new DbCard
            {
                Name = "FatLooser"
            };

            p.Cards.Add(card);
            p.SaveChanges();
            var query = p.Cards.ToList();

            foreach (var q in query)
            {
                Console.WriteLine($"{q.Name} : {q.Id}");
            }
        }
Beispiel #30
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"));
        }