示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="email"></param>
        /// <param name="cards"></param>
        /// <returns></returns>
        public static bool AddPersonCardsByEmail(string email, List <Card> cards)
        {
            Person person = null;

            try
            {
                using (var db = new ClonestoneFSEntities())
                {
                    person = db.AllPersons.Where(u => u.Email == email).FirstOrDefault();
                    if (person == null)
                    {
                        throw new Exception("UserDoesNotExist");
                    }

                    /// gehe alle Karten durch die dieser person hinzugefügt werden sollen
                    foreach (var card in cards)
                    {
                        /// ermittle ob die Person diese Karte bereits hat
                        var personCard = person.AllPersonCards.Where(x => x.ID_Card == card.ID).FirstOrDefault();

                        /// die person hat diese Karte noch NICHT
                        if (personCard == null)
                        {
                            personCard               = new PersonCard();
                            personCard.Person        = person;
                            personCard.NumberOfCards = 1;
                            person.AllPersonCards.Add(personCard);
                        }
                        else /// die person hat diese karte schon einmal
                        {
                            personCard.NumberOfCards += 1;  /// erhöhe die anzahl dieser karte um eins
                        }
                    }

                    db.SaveChanges();
                    return(true);
                }
            }
            catch (Exception e)
            {
                Debugger.Break();
                Writer.LogError(e);
                return(false);
            }
        }
示例#2
0
        public void ConvertFrom_string_object()
        {
            // Arrange
            var value = new PersonCard()
            {
                Name    = "Sabrina Styles",
                Age     = 42,
                Friends = 872
            };

            // Act
            var objectNode = JsonNode.ConvertFrom(value) as JsonObjectNode;

            // Assert
            Assert.IsNotNull(objectNode);
            Assert.AreEqual(3, objectNode.Count);
            Assert.AreEqual("Sabrina Styles", (objectNode["Name"] as JsonStringNode).Value);
            Assert.AreEqual(42, (objectNode["Age"] as JsonIntegerNode).Value);
            Assert.AreEqual(872, (objectNode["Friends"] as JsonIntegerNode).Value);
        }
示例#3
0
 /// <summary>
 /// Сериализация наследников PersonCard
 /// </summary>
 /// <param name="person">
 /// Объект пакета
 /// </param>
 /// <returns>
 /// The <see cref="MemoryStream"/>.
 /// </returns>
 public static MemoryStream SerializePersonCard(PersonCard person)
 {
     return(SerializeToMemoryStream(person, "ZPIMessageBatch"));
 }
示例#4
0
 /// <summary>
 /// Сериализация наследников PersonCard
 /// </summary>
 /// <param name="person">
 /// Объект пакета
 /// </param>
 /// <param name="fileName">
 /// Имя файла
 /// </param>
 public static void SerializePersonCard(PersonCard person, string fileName)
 {
     SerializeBasePersonTemplate(person, fileName, "ZPIMessageBatch");
 }
示例#5
0
        public static BuyResult BuyPack(int id, string email)
        {
            BuyResult result = BuyResult.Success;

            if (id <= 0)
            {
                throw new ArgumentException("Invalid Value", nameof(id));
            }

            if (string.IsNullOrEmpty(email))
            {
                throw new ArgumentNullException(nameof(email));
            }

            try
            {
                using (var context = new ClonestoneFSEntities())
                {
                    Person user = context.AllPersons.FirstOrDefault(x => x.Email == email);
                    if (user == null)
                    {
                        throw new ArgumentException("Invalid value", nameof(email));
                    }

                    Pack cardPack = context.AllPacks.FirstOrDefault(x => x.ID == id);
                    if (cardPack == null)
                    {
                        throw new ArgumentException("Invalid value", nameof(id));
                    }


                    if (cardPack.IsMoney == false)
                    {
                        if (user.Currencybalance < cardPack.Packprice)
                        {
                            result = BuyResult.NotEnoughMoney;
                        }
                        else
                        {
                            user.Currencybalance -= (int)cardPack.Packprice;

                            Order purchase = new Order()
                            {
                                ID_Pack       = id,
                                ID_Person     = user.ID,
                                NumberOfPacks = 1,
                                Orderdate     = DateTime.Now
                            };
                            context.AllOrders.Add(purchase);


                            int count = context.AllCards.Count();

                            //List<Card> userCards = new List<Card>();

                            /// create cards at random
                            for (int numberOfCard = 0; numberOfCard < cardPack.Cardquantity; numberOfCard++)
                            {
                                /// get a valid idCard (generated by random)
                                Card randomCard = context.AllCards.OrderBy(x => x.ID).Skip(RandomNumberGenerator.Next(0, count)).Take(1).Single();

                                /// save new card to userCards

                                /// if card is already an userCard
                                /// increase number
                                PersonCard personCard = user.AllPersonCards.Where(x => x.ID == randomCard.ID).FirstOrDefault();
                                if (personCard != null)
                                {
                                    personCard.NumberOfCards++;
                                }
                                else /// else - add new userCard
                                {
                                    personCard = new PersonCard()
                                    {
                                        ID_Person     = user.ID,
                                        ID_Card       = randomCard.ID,
                                        NumberOfCards = 1
                                    };
                                    context.AllPersonCards.Add(personCard);
                                }
                            }
                            context.SaveChanges();
                        }
                    }

                    else if (cardPack.IsMoney == true)
                    {
                        Order purchase = new Order()
                        {
                            ID_Pack       = id,
                            ID_Person     = user.ID,
                            NumberOfPacks = 1,
                            Orderdate     = DateTime.Now
                        };
                        context.AllOrders.Add(purchase);


                        int currentBalance = UserManager.GetCurrencyBalanceByEmail(user.Email);

                        int sumBalance = ((int)(currentBalance + GetCardPackById(id).DiamondValue)) * (int)purchase.NumberOfPacks;

                        bool isUpdated = UserManager.BalanceUpdateByEmail(user.Email, sumBalance);

                        context.SaveChanges();
                    }
                }
            }

            catch (Exception ex)
            {
                throw ex;
            }

            return(result);
        }
示例#6
0
        public SearchPage(Frame frame, string SearchParam)
        {
            InitializeComponent();
            Results_Grid.RowDefinitions.Add(new RowDefinition());

            var SearchResults = ApiMethods.SearchFor(SearchParam);

            foreach (var result in SearchResults.results)
            {
                switch ((string)result.media_type)
                {
                case ("movie"):
                    BitmapImage Movie_Image = ApiMethods.GetImage((string)result.poster_path, "w400");

                    PersonCard Movie_Card = new PersonCard(
                        frame: frame,
                        id: (string)result.id,
                        type: "movie",
                        img: Movie_Image,
                        field1: (string)result.original_title,
                        field2: "rating:",
                        field3: (string)result.vote_average
                        );
                    Movie_Card.Margin     = new Thickness(5);
                    Movie_Card.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#3c366b"));
                    AddToGrid(Movie_Card, CurrentColumn, CurrentRow);
                    break;

                case ("tv"):
                    BitmapImage TV_Image = ApiMethods.GetImage((string)result.backdrop_path, "w400");

                    PersonCard Tv_Card = new PersonCard(
                        frame: frame,
                        id: (string)result.id,
                        type: "movie",
                        img: TV_Image,
                        field1: (string)result.name,
                        field2: "rating:",
                        field3: (string)result.vote_average
                        );
                    Tv_Card.Margin     = new Thickness(5);
                    Tv_Card.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#3c366b"));
                    AddToGrid(Tv_Card, CurrentColumn, CurrentRow);
                    break;

                case ("person"):
                    BitmapImage DefaultImage = new BitmapImage(new Uri(@"https://www.praxisemr.com/images/testimonials_images/dr_profile.jpg"));
                    if ((string)result.profile_path != null)
                    {
                        DefaultImage = ApiMethods.GetImage((string)result.profile_path, "w400");
                    }

                    PersonCard person_Card = new PersonCard(
                        frame: frame,
                        id: (string)result.id,
                        type: "person",
                        img: DefaultImage,
                        field1: (string)result.name,
                        field2: "Known for:",
                        field3: (string)result.known_for_department
                        );
                    person_Card.Margin     = new Thickness(5);
                    person_Card.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#3c366b"));
                    AddToGrid(person_Card, CurrentColumn, CurrentRow);
                    break;
                }
                Console.WriteLine(Results_Grid.Children.Count);
            }
        }
示例#7
0
        private void PopulatePersonView()
        {
            List<Widget> children = new List<Widget> (vbox.Children);
            foreach (Widget child in children) {
                vbox.Remove (child);
                try {
                    child.Destroy ();
                } catch {}
            }

            // personCardMap.Clear ();

            if (model == null) {
                Logger.Debug ("PersonView.PopulatePersonView returning since the model is null.");
                return;
            }

            TreeIter iter;

            // Loop through the model, create the PersonCard objects and add
            // them into the vbox.
            if (model.GetIterFirst (out iter)) {
                do {
                    Person person = model.GetValue (iter, 0) as Person;
                    if (person == null)
                        continue;

                    TreePath path = model.GetPath (iter);
                    PersonCard card = new PersonCard(person);
                    card.Size = personCardSize;
                    card.ShowAll ();
                    vbox.PackStart (card, false, false, 0);
                    vbox.ReorderChild(card, path.Indices [0]);
                    // personCardMap[iter] = card;
                } while (model.IterNext (ref iter));
            }
        }
示例#8
0
        private void OnPersonRowInserted(object sender, RowInsertedArgs args)
        {
            //			Logger.Debug("PersonView:OnPersonRowInserted Called");
            TreePath path = model.GetPath (args.Iter);
            PersonCard card = new PersonCard();

            Person person = model.GetValue (args.Iter, 0) as Person;
            if (person != null) {
                card.Person = person;
            }

            card.Size = personCardSize;
            card.ShowAll ();
            vbox.PackStart (card, false, false, 0);
            vbox.ReorderChild(card, path.Indices [0]);
            personCardMap[args.Iter] = card;
        }