예제 #1
0
        public ActionResult Index()
        {
            Character character = this.HttpContext.Items["Character"] as Character;

            if (character == null)
            {
                return(HttpNotFound());
            }

            var query = from r1 in db.GeneratedItems
                        from r2 in db.Items
                        join r3 in db.Images on r2.ImageId equals r3.ID into R3
                        from r8 in R3.DefaultIfEmpty()
                        join r4 in db.Affixes on r1.PrefixId equals r4.Id into R4
                        from r5 in R4.DefaultIfEmpty()
                        join r6 in db.Affixes on r1.SuffixId equals r6.Id into R6
                        from r7 in R6.DefaultIfEmpty()
                        where r1.CharacterId == character.Id && r1.ItemId == r2.Id
                        select new ItemViewModel
            {
                GeneratedItem = r1,
                Item          = r2,
                Image         = r8 != null ? r8 : null,
                Prefix        = r5 != null ? r5 : null,
                Suffix        = r7 != null ? r7 : null
            };

            List <ItemViewModel> characterItems = query.ToList();

            return(View(characterItems));
        }
예제 #2
0
        public ActionResult Sell(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Character character = this.HttpContext.Items["Character"] as Character;

            if (character == null)
            {
                return(HttpNotFound());
            }

            var query = from r1 in db.GeneratedItems
                        from r2 in db.Items
                        join r4 in db.Affixes on r1.PrefixId equals r4.Id into R4
                        from r5 in R4.DefaultIfEmpty()
                        join r6 in db.Affixes on r1.SuffixId equals r6.Id into R6
                        from r7 in R6.DefaultIfEmpty()
                        where r1.Id == id && r1.CharacterId == character.Id && r1.ItemId == r2.Id
                        select new ItemViewModel
            {
                GeneratedItem = r1,
                Item          = r2,
                Prefix        = r5 != null ? r5 : null,
                Suffix        = r7 != null ? r7 : null
            };

            var item = query.FirstOrDefault();

            if (item == null)
            {
                return(RedirectToAction("Index"));
            }

            int price = itemService.GetCalculatedPrice(item.Item != null ? item.Item.Price : 0,
                                                       item.Prefix != null ? item.Prefix.Price : 0,
                                                       item.Suffix != null ? item.Suffix.Price : 0,
                                                       item.GeneratedItem != null ? item.GeneratedItem.Durability : 0,
                                                       item.Item != null ? item.Item.Durability : 1);

            try
            {
                character.Gold           += price;
                db.Entry(character).State = EntityState.Modified;
                db.GeneratedItems.Remove(item.GeneratedItem);
                db.SaveChanges();
            }
            catch (Exception)
            {
                FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd. Skontaktuj się z administratorem.");
            }

            return(RedirectToAction("Index"));
        }
예제 #3
0
        public ActionResult Index()
        {
            Character character = this.HttpContext.Items["Character"] as Character;

            if (character == null)
            {
                return(HttpNotFound());
            }

            var query2 = from r1 in db.GeneratedItems
                         from r2 in db.Items
                         join r3 in db.Images on r2.ImageId equals r3.ID into R3
                         from r8 in R3.DefaultIfEmpty()
                         join r4 in db.Affixes on r1.PrefixId equals r4.Id into R4
                         from r5 in R4.DefaultIfEmpty()
                         join r6 in db.Affixes on r1.SuffixId equals r6.Id into R6
                         from r7 in R6.DefaultIfEmpty()
                         where r1.CharacterId == character.Id && r1.ItemId == r2.Id
                         select new ItemViewModel
            {
                GeneratedItem = r1,
                Item          = r2,
                Image         = r8 != null ? r8 : null,
                Prefix        = r5 != null ? r5 : null,
                Suffix        = r7 != null ? r7 : null
            };

            List <ItemViewModel> characterItems = query2.ToList();

            EquipmentViewModel equipmentViewModel = new EquipmentViewModel();

            equipmentViewModel.EquippedItems =
                characterItems.FindAll(i => i.GeneratedItem.Status == ItemStatus.Equipped);
            equipmentViewModel.BackpackItems =
                characterItems.FindAll(i => i.GeneratedItem.Status == ItemStatus.Bagpack);
            equipmentViewModel.ChestItems =
                characterItems.FindAll(i => i.GeneratedItem.Status == ItemStatus.Chest);

            return(View(equipmentViewModel));
        }