public ActionResult Login(LoginUserViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var query = from u in db.Users where u.Name == model.Username select u; var user = query.FirstOrDefault(); if (user == null || !PasswordHashService.ValidatePassword(model.Password, user.Password)) { FlashMessageHelper.SetMessage(this, FlashMessageType.Warning, "Autoryzacja użytkownika nie przebiegła pomyślnie."); return(View(model)); } UserSessionContext us = new UserSessionContext(HttpContext); us.SetUserId(user.Id); return(RedirectToAction("Index", "Character")); }
public ActionResult Create(Message message, string ToUserName) { Character character = this.HttpContext.Items["Character"] as Character; message.FromUser = character.Name; var query = from d1 in db.Characters where d1.Name == ToUserName select d1.Id; if (ToUserName == character.Name) { var oneCharacter = query.FirstOrDefault(); message.ToUserId = oneCharacter; message.Type = MessageType.User; } else { FlashMessageHelper.SetMessage(this, FlashMessageType.Warning, "Nazwa użytkownika jest nie poprawna lub nie istnieje w bazie danych."); return(View("Create")); } if (ModelState.IsValid) { db.Messages.Add(message); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(message)); }
public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var query = from a in db.Affixes where a.Id == id select a; var affix = query.FirstOrDefault(); if (affix == null) { return(HttpNotFound()); } try { db.Affixes.Remove(affix); db.SaveChanges(); FlashMessageHelper.SetMessage(this, FlashMessageType.Success, "Usunięcie danych przebiegło pomyślnie."); } catch (Exception) { FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd związany z usuwaniem danych."); } return(RedirectToAction("Index")); }
public ActionResult Edit(Affix affix) { if (!Enum.IsDefined(typeof(AffixType), affix.Type)) { ModelState.AddModelError("Type", new Exception()); } try { if (ModelState.IsValid) { db.Entry(affix).State = EntityState.Modified; db.SaveChanges(); FlashMessageHelper.SetMessage(this, FlashMessageType.Success, "Aktualizacja danych przebiegła pomyślnie."); return(RedirectToAction("Index")); } FlashMessageHelper.SetMessage(this, FlashMessageType.Info, "Nie można zaktualizować danych. Należy poprawić zaistniałe błędy."); } catch (DbUpdateConcurrencyException) { FlashMessageHelper.SetMessage(this, FlashMessageType.Warning, "Dane został zaktualizowane przez inną osobę. Należy odświeżyć stronę w celu wczytania nowych danych."); } catch (Exception) { FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd związany z aktualizowaniem danych."); } return(View(affix)); }
public ActionResult Create(Affix affix) { if (!Enum.IsDefined(typeof(AffixType), affix.Type)) { ModelState.AddModelError("Type", new Exception()); } try { if (ModelState.IsValid) { db.Affixes.Add(affix); db.SaveChanges(); FlashMessageHelper.SetMessage(this, FlashMessageType.Success, "Zapisanie nowych danych przebiegło pomyślnie."); return(RedirectToAction("Index")); } FlashMessageHelper.SetMessage(this, FlashMessageType.Info, "Nie można zapisać nowych danych. Należy poprawić zaistniałe błędy."); } catch (Exception) { FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd związany z zapisem nowych danych."); } return(View(affix)); }
public ActionResult CreateArmor(ShieldItemViewModel armorItemViewModel) { Item item = new Item() { Type = ItemType.Armor, Name = armorItemViewModel.Name, Durability = armorItemViewModel.Durability, Price = armorItemViewModel.Price, PrimaryMinValue = armorItemViewModel.Armor, PrimaryMaxValue = armorItemViewModel.Armor, QualityLevel = armorItemViewModel.QualityLevel, RequireStrength = armorItemViewModel.RequireStrength, }; try { if (ModelState.IsValid) { db.Items.Add(item); db.SaveChanges(); FlashMessageHelper.SetMessage(this, FlashMessageType.Success, "Zapisanie nowych danych przebiegło pomyślnie."); return(RedirectToAction("Index")); } FlashMessageHelper.SetMessage(this, FlashMessageType.Info, "Nie można zapisać nowych danych. Należy poprawić zaistniałe błędy."); } catch (Exception) { FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd związany z zapisem nowych danych."); } return(View(armorItemViewModel)); }
public ActionResult Create(HttpPostedFileBase file, ImageCategory category) { Image image = new Image(); try { if (file == null || file.ContentLength <= 0) { throw new Exception("Plik pusty"); } if (file.ContentLength > 204800) { throw new Exception("Uwaga wielkość pliku przekracza 200kb."); } // Get file info var fileName = Path.GetFileName(file.FileName); //nazwa pliku var imageName = Path.GetFileNameWithoutExtension(fileName); var imageExtension = ""; var contentLength = file.ContentLength; //wielkosc pliku var contentType = file.ContentType; //typ pliku if (contentType == "image/jpeg") { imageExtension = "jpg"; } else if (contentType == "image/png") { imageExtension = "png"; } if (imageExtension == "") { throw new Exception("Uwaga niewłaściwy format zdjęcia. Akceptowane formaty: jpg, png."); } byte[] imageBytes = new byte[contentLength - 1]; using (var binaryReader = new BinaryReader(file.InputStream)) { imageBytes = binaryReader.ReadBytes(file.ContentLength); } image.FileName = String.Format("{0:yyyyMMddHHmmss}.{1}", DateTime.Now, imageExtension); image.Data = imageBytes; image.Type = contentType; image.Category = category; db.Images.Add(image); db.SaveChanges(); FlashMessageHelper.SetMessage(this, FlashMessageType.Success, "Dodanie zdjęcia przebiegło pomyślnie."); return(RedirectToAction("Index")); } catch (Exception e) { FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd związany z zapisem danych. " + e.Message); } return(View(image)); }
public ActionResult Create(Event one_event) { try { if (ModelState.IsValid) { db.Events.Add(one_event); db.SaveChanges(); FlashMessageHelper.SetMessage(this, FlashMessageType.Success, "Zapisanie nowych danych przebiegło pomyślnie."); return(RedirectToAction("Index")); } FlashMessageHelper.SetMessage(this, FlashMessageType.Info, "Nie można zapisać nowych danych. Należy poprawić zaistniałe błędy."); } catch (Exception) { FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd związany z zapisem nowych danych."); } var query = from a in db.Locations where a.ID == one_event.LocationId select a; var fail_event = query.FirstOrDefault(); CreateEventViewModel setItemViewModel = new CreateEventViewModel() { Location = fail_event, Event = one_event }; return(View(setItemViewModel)); }
public ActionResult Edit(Location location) { var query = from i in db.Locations where i.ID == location.ID select i; if (!query.Any()) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } try { if (ModelState.IsValid) { db.Entry(location).State = EntityState.Modified; db.SaveChanges(); FlashMessageHelper.SetMessage(this, FlashMessageType.Success, "Aktualizacja danych przebiegła pomyślnie."); return(RedirectToAction("Index")); } FlashMessageHelper.SetMessage(this, FlashMessageType.Info, "Nie można zaktualizować danych. Należy poprawić zaistniałe błędy."); } catch (DbUpdateConcurrencyException) { FlashMessageHelper.SetMessage(this, FlashMessageType.Warning, "Dane został zaktualizowane przez inną osobę. Należy odświeżyć stronę w celu wczytania nowych danych."); } catch (Exception) { FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd związany z aktualizowaniem danych."); } return(View(location)); }
public ActionResult Edit(int?id, HttpPostedFileBase file, ImageCategory category) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var query = from i in db.Images where i.ID == id select i; var image = query.FirstOrDefault(); try { if (!Enum.IsDefined(typeof(ImageCategory), category)) { throw new Exception("Niewłaściwa Katygoria"); } if (file != null) { var fileName = Path.GetFileName(file.FileName); //nazwa pliku var imageName = Path.GetFileNameWithoutExtension(fileName); var imageExtension = ""; var contentLength = file.ContentLength; //wielkosc pliku var contentType = file.ContentType; //typ pliku byte[] imageBytes = new byte[contentLength - 1]; using (var binaryReader = new BinaryReader(file.InputStream)) { imageBytes = binaryReader.ReadBytes(file.ContentLength); } image.FileName = String.Format("{0:yyyyMMddHHmmss}.{1}", DateTime.Now, imageExtension); image.Data = imageBytes; image.Type = contentType; } image.Category = category; db.Entry(image).State = EntityState.Modified; db.SaveChanges(); FlashMessageHelper.SetMessage(this, FlashMessageType.Success, "Aktualizacja danych przebiegła pomyślnie."); return(RedirectToAction("Index")); } catch (DbUpdateConcurrencyException) { FlashMessageHelper.SetMessage(this, FlashMessageType.Warning, "Dane zostały zaktualizowane przez inną osobę. Należy odświeżyć stronę w celu wczytania nowych danych."); } catch (Exception e) { FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd związany z aktualizowaniem danych. " + e.Message); } return(View(image)); }
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")); }
public ActionResult Delete(IEnumerable <int> messages_checkbox) { if (messages_checkbox == null) { FlashMessageHelper.SetMessage(this, FlashMessageType.Warning, "Nie zaznaczono wiadomości"); return(RedirectToAction("Index")); } db.Messages.Where(x => messages_checkbox.Contains(x.Id)).ToList().ForEach(x => db.Messages.Remove(x)); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(Character character) { if (!Enum.IsDefined(typeof(CharacterClass), character.Class)) { return(HttpNotFound()); } User user = this.HttpContext.Items["User"] as User; var query = from c in db.Characters where c.UserId == user.Id select c; if (query.Any()) { return(RedirectToAction("Index")); } var query2 = from c in db.Characters where c.Name == character.Name select c; if (query2.Any()) { ModelState.AddModelError("Name", "Nazwa postaci jest już zajęta."); } if (!ModelState.IsValid) { return(View(character)); } character.UserId = user.Id; character.Experience = 0; character.Gold = 0; character.RenewalTime = DateTime.Now; character.AvailableMoves = 0; try { db.Characters.Add(character); db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception) { FlashMessageHelper.SetMessage(this, FlashMessageType.Warning, "Wystąpił nieoczekiwany błąd."); } return(View(character)); }
public ActionResult Edit(Event oneEvent) { var query = from i in db.Events where i.Id == oneEvent.Id select i; if (!query.Any()) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } try { if (ModelState.IsValid) { db.Entry(oneEvent).State = EntityState.Modified; db.SaveChanges(); FlashMessageHelper.SetMessage(this, FlashMessageType.Success, "Aktualizacja danych przebiegła pomyślnie."); return(RedirectToAction("Index")); } FlashMessageHelper.SetMessage(this, FlashMessageType.Info, "Nie można zaktualizować danych. Należy poprawić zaistniałe błędy."); } catch (DbUpdateConcurrencyException) { FlashMessageHelper.SetMessage(this, FlashMessageType.Warning, "Dane został zaktualizowane przez inną osobę. Należy odświeżyć stronę w celu wczytania nowych danych."); } catch (Exception) { FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd związany z aktualizowaniem danych."); } var query2 = from a in db.Locations where a.ID == oneEvent.LocationId select a; var fail_event = query2.FirstOrDefault(); CreateEventViewModel setItemViewModel = new CreateEventViewModel() { Location = fail_event, Event = oneEvent }; return(View(setItemViewModel)); }
public ActionResult ChangeStatusToChest(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 i in db.GeneratedItems where i.CharacterId == character.Id select i; List <GeneratedItem> items = query.ToList(); var item = items.FirstOrDefault(i => i.Id == id && i.Status != ItemStatus.Chest); if (item == null) { return(RedirectToAction("Index")); } if (items.Count(i => i.Status == ItemStatus.Chest) >= 10) { FlashMessageHelper.SetMessage(this, FlashMessageType.Info, "Twoja skrzynia jest już pełna"); return(RedirectToAction("Index")); } try { item.Status = ItemStatus.Chest; db.Entry(item).State = EntityState.Modified; db.SaveChanges(); } catch (Exception) { FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd. Skontaktuj się z administratorem."); } return(RedirectToAction("Index")); }
public ActionResult CreateWeapon(WeaponItemViewModel weaponItemViewModel) { if (!Enum.IsDefined(typeof(WeaponType), (WeaponType)weaponItemViewModel.Type)) { ModelState.AddModelError("Type", new Exception()); } Item item = new Item() { Type = ItemType.Weapon, SubType = (SubType)weaponItemViewModel.Type, Name = weaponItemViewModel.Name, Durability = weaponItemViewModel.Durability, Price = weaponItemViewModel.Price, PrimaryMinValue = weaponItemViewModel.MinDamage, PrimaryMaxValue = weaponItemViewModel.MaxDamage, QualityLevel = weaponItemViewModel.QualityLevel, RequireStrength = weaponItemViewModel.RequireStrength, AttackSpeed = weaponItemViewModel.AttackSpeed, ChanceToHit = weaponItemViewModel.ChanceToHit }; try { if (ModelState.IsValid) { db.Items.Add(item); db.SaveChanges(); FlashMessageHelper.SetMessage(this, FlashMessageType.Success, "Zapisanie nowych danych przebiegło pomyślnie."); return(RedirectToAction("Index")); } FlashMessageHelper.SetMessage(this, FlashMessageType.Info, "Nie można zapisać nowych danych. Należy poprawić zaistniałe błędy."); } catch (Exception) { FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd związany z zapisem nowych danych."); } return(View(weaponItemViewModel)); }
public ActionResult Create(Monster monster) { try { if (ModelState.IsValid) { db.Monsters.Add(monster); db.SaveChanges(); FlashMessageHelper.SetMessage(this, FlashMessageType.Success, "Zapisanie nowych danych przebiegło pomyślnie."); return(RedirectToAction("Index")); } FlashMessageHelper.SetMessage(this, FlashMessageType.Info, "Nie można zapisać nowych danych. Należy poprawić zaistniałe błędy."); } catch (Exception) { FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd związany z zapisem nowych danych."); } return(View(monster)); }
public ActionResult Edit(Item item) { if (!Enum.IsDefined(typeof(ItemType), item.Type)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if ((item.Type == ItemType.Weapon && !Enum.IsDefined(typeof(WeaponType), (WeaponType)item.SubType)) || (item.Type == ItemType.Jewelry && !Enum.IsDefined(typeof(JewelryType), (JewelryType)item.SubType))) { ModelState.AddModelError("SubType", new Exception()); } try { if (ModelState.IsValid) { db.Entry(item).State = EntityState.Modified; db.SaveChanges(); FlashMessageHelper.SetMessage(this, FlashMessageType.Success, "Aktualizacja danych przebiegła pomyślnie."); return(RedirectToAction("Index")); } FlashMessageHelper.SetMessage(this, FlashMessageType.Info, "Nie można zaktualizować danych. Należy poprawić zaistniałe błędy."); } catch (DbUpdateConcurrencyException) { FlashMessageHelper.SetMessage(this, FlashMessageType.Warning, "Dane zostały zaktualizowane przez inną osobę. Należy odświeżyć stronę w celu wczytania nowych danych."); } catch (Exception) { FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd związany z aktualizowaniem danych."); } return(GetEditItemView(item)); }
public ActionResult CreateJewelry(JewelryItemViewModel jewelryItemViewModel) { if (!Enum.IsDefined(typeof(JewelryType), (JewelryType)jewelryItemViewModel.Type)) { ModelState.AddModelError("Type", new Exception()); } Item item = new Item() { Type = ItemType.Jewelry, SubType = (SubType)jewelryItemViewModel.Type, Name = jewelryItemViewModel.Name, Durability = jewelryItemViewModel.Durability, Price = jewelryItemViewModel.Price, QualityLevel = jewelryItemViewModel.QualityLevel, }; try { if (ModelState.IsValid) { db.Items.Add(item); db.SaveChanges(); FlashMessageHelper.SetMessage(this, FlashMessageType.Success, "Zapisanie nowych danych przebiegło pomyślnie."); return(RedirectToAction("Index")); } FlashMessageHelper.SetMessage(this, FlashMessageType.Info, "Nie można zapisać nowych danych. Należy poprawić zaistniałe błędy."); } catch (Exception) { FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd związany z zapisem nowych danych."); } return(View(jewelryItemViewModel)); }
public ActionResult Travel(int?locationID) { Character character = this.HttpContext.Items["Character"] as Character; if (locationID == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (character.AvailableMoves == 0) { FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Nie masz wystarczającej ilości ruchów. Spróbuj za chwilę..."); return(RedirectToAction("Index")); } EventLog eventlog = this.HttpContext.Items["NotCompletedEventLog"] as EventLog; if (eventlog != null) { FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Jesteś aktualnie w trakcie wyprawy. Spróbuj za chwilę..."); return(RedirectToAction("Index")); } if (character.AvailableMoves == 10) { character.RenewalTime = DateTime.Now; } character.AvailableMoves -= 1; CharacterService characterserv = new CharacterService(); CharacterViewModel characterview = characterserv.GetCharacterViewModel(character, new List <ItemViewModel>()); var query = from e in db.Events where e.Type == EventType.Random select e; var querycounter = query.Count(); var query2 = from e in db.Events from m in db.Monsters from i in db.Images where e.Type == EventType.Monster && e.MonsterId == m.Id && m.ImageId == i.ID && m.Level <= characterview.Level select e; var query3 = from e in query.Concat(query2) from l in db.Locations from i in db.Images where locationID == l.ID && e.LocationId == locationID && l.ImageId == i.ID orderby e.Id select e; int eventcounter = query3.Count(); if (eventcounter <= 0) { return(HttpNotFound()); } Random dice = new Random(); int random = dice.Next(0, eventcounter); var winEvent = query3.Skip(random).Take(1).FirstOrDefault(); if (winEvent == null) { return(HttpNotFound()); } EventLog log = new EventLog(); log.CharacterId = character.Id; log.EventId = winEvent.Id; log.Created_at = DateTime.Now; log.IsCompleted = false; try { db.Entry(character).State = EntityState.Modified; db.EventLogs.Add(log); db.SaveChanges(); } catch (Exception) { FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd związany z aktualizowaniem danych."); return(RedirectToAction("Index")); } return(RedirectToAction("Index")); }
public ActionResult Set(ImageCategory?category, int?id, int?imageId) { if (category == null || !Enum.IsDefined(typeof(ImageCategory), category)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (category == ImageCategory.Item) { var query = from i in db.Items where i.Id == id select i; var item = query.FirstOrDefault(); if (item == null) { return(HttpNotFound()); } if (imageId == null) { return(Set(ImageCategory.Item, item.Id)); } var query2 = from i in db.Images where i.ID == imageId select i; var image = query2.FirstOrDefault(); if (image == null) { return(HttpNotFound()); } try { item.ImageId = (int)imageId; db.Entry(item).State = EntityState.Modified; db.SaveChanges(); FlashMessageHelper.SetMessage(this, FlashMessageType.Success, "Obrazek został pomyślnie przypisany do przedmiotu."); return(RedirectToAction("Details", "Item", new { id = item.Id })); } catch (Exception) { FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd z przypisaniem obrazka do przedmiotu."); } return(Set(ImageCategory.Item, item.Id)); } else if (category == ImageCategory.Monster) { var query = from i in db.Monsters where i.Id == id select i; var monster = query.FirstOrDefault(); if (monster == null) { return(HttpNotFound()); } if (imageId == null) { return(Set(ImageCategory.Monster, monster.Id)); } var query2 = from i in db.Images where i.ID == imageId select i; var image = query2.FirstOrDefault(); if (image == null) { return(HttpNotFound()); } try { monster.ImageId = (int)imageId; db.Entry(monster).State = EntityState.Modified; db.SaveChanges(); FlashMessageHelper.SetMessage(this, FlashMessageType.Success, "Obrazek został pomyślnie przypisany do potwora."); return(RedirectToAction("Details", "Monster", new { id = monster.Id })); } catch (Exception) { FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd z przypisaniem obrazka do potwora."); } return(Set(ImageCategory.Monster, monster.Id)); } else if (category == ImageCategory.Location) { var query = from i in db.Locations where i.ID == id select i; var location = query.FirstOrDefault(); if (location == null) { return(HttpNotFound()); } if (imageId == null) { return(Set(ImageCategory.Location, location.ID)); } var query2 = from i in db.Images where i.ID == imageId select i; var image = query2.FirstOrDefault(); if (image == null) { return(HttpNotFound()); } try { location.ImageId = (int)imageId; db.Entry(location).State = EntityState.Modified; db.SaveChanges(); FlashMessageHelper.SetMessage(this, FlashMessageType.Success, "Obrazek został pomyślnie przypisany do lokacji."); return(RedirectToAction("Details", "Location", new { id = location.ID })); } catch (Exception) { FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd z przypisaniem obrazka do lokacji."); } return(Set(ImageCategory.Location, location.ID)); } return(HttpNotFound()); }
public ActionResult ChangeStatusToEquipped(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 where r1.CharacterId == character.Id && r1.ItemId == r2.Id && r1.Id == id && r1.Status == ItemStatus.Chest select new ItemViewModel { GeneratedItem = r1, Item = r2, }; // przedmiot do założenia ItemViewModel itemToEquip = query.FirstOrDefault(); if (itemToEquip == null) { return(RedirectToAction("Index")); } var query2 = from r1 in db.GeneratedItems from r2 in db.Items where r1.CharacterId == character.Id && r1.ItemId == r2.Id && r1.Status == ItemStatus.Equipped select new ItemViewModel { GeneratedItem = r1, Item = r2, }; // lista przedmiotów postaci List <ItemViewModel> equippedItems = query2.ToList(); CharacterViewModel characterViewModel = cs.GetCharacterViewModel(character, equippedItems); if (characterViewModel.Strength < itemToEquip.Item.RequireStrength) { FlashMessageHelper.SetMessage(this, FlashMessageType.Info, "Nie możesz założyć tego przedmiotu, masz za mało siły."); return(RedirectToAction("Index")); } if (itemToEquip.Item.Type == ItemType.Armor) { if (equippedItems.Count(i => i.Item.Type == ItemType.Armor) == 0) { itemToEquip.GeneratedItem.Status = ItemStatus.Equipped; } } else if (itemToEquip.Item.Type == ItemType.Jewelry) { if (itemToEquip.Item.SubType == SubType.Amulet) { if (equippedItems.Count(i => i.Item.SubType == SubType.Amulet) == 0) { itemToEquip.GeneratedItem.Status = ItemStatus.Equipped; } } else { if (equippedItems.Count(i => i.Item.SubType == SubType.Ring) < 2) { itemToEquip.GeneratedItem.Status = ItemStatus.Equipped; } } } else if (itemToEquip.Item.Type == ItemType.Weapon) { if (equippedItems.Count(i => i.Item.Type == ItemType.Weapon) == 0) { if (equippedItems.Count(i => i.Item.Type == ItemType.Shield) == 0) { itemToEquip.GeneratedItem.Status = ItemStatus.Equipped; } } } else if (equippedItems.Count(i => i.Item.Type == ItemType.Shield) == 0) { if (equippedItems.Count(i => i.Item.SubType == SubType.TwoHanded) == 0) { itemToEquip.GeneratedItem.Status = ItemStatus.Equipped; } } if (itemToEquip.GeneratedItem.Status != ItemStatus.Equipped) { FlashMessageHelper.SetMessage(this, FlashMessageType.Info, "Nie masz wolnego miejsca by założyć ten przedmiot."); return(RedirectToAction("Index")); } try { db.Entry(itemToEquip.GeneratedItem).State = EntityState.Modified; db.SaveChanges(); } catch (Exception) { FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd. Skontaktuj się z administratorem."); } return(RedirectToAction("Index")); }