Exemplo n.º 1
0
        private void UpdateInstructorTags(string[] selectedTags, Infos infosToUpdate)
        {
            if (selectedTags == null)
            {
                infosToUpdate.InfoTag = new List <InfoTag>();
                return;
            }

            var selectedTagsHS = new HashSet <string>(selectedTags);
            var instructorTags = new HashSet <int>(infosToUpdate.InfoTag.Select(c => c.Tag.Id));

            foreach (var tag in context.Tag)
            {
                if (selectedTagsHS.Contains(tag.Id.ToString()))
                {
                    if (!instructorTags.Contains(tag.Id))
                    {
                        infosToUpdate.InfoTag.Add(new InfoTag {
                            InfoId = infosToUpdate.Id, TagId = tag.Id
                        });
                    }
                }
                else
                {
                    if (instructorTags.Contains(tag.Id))
                    {
                        InfoTag tagToRemove = infosToUpdate.InfoTag.FirstOrDefault(i => i.TagId == tag.Id);
                        context.Remove(tagToRemove);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public IActionResult ChangeInfoTag(string imageId, string TagList)
        {
            if (ModelState.IsValid)
            {
                if (TagList != null)
                {
                    var listOfTags = repositoryTag.InfoTags.Where(p => p.ImageID == Convert.ToInt32(imageId)).ToList();
                    foreach (var item in listOfTags)
                    {
                        repositoryTag.DeleteTag(item.id);
                    }
                    var imgInfo = repositoryGall.Images.Where(t => t.ImageID == Convert.ToInt32(imageId));

                    foreach (var item in imgInfo)
                    {
                        item.Info = TagList;
                    }
                    string[] arr = TagList.Split("#");
                    for (int i = 1; i < arr.Length; i++)
                    {
                        var tag = new InfoTag
                        {
                            TagName = arr[i].ToLower(),
                            ImageID = Convert.ToInt32(imageId)
                        };
                        repositoryTag.SaveTag(tag);
                    }
                    TempData["message"] = " tag was changed";
                }
            }
            return(RedirectToAction("GalleryList"));
        }
Exemplo n.º 3
0
    internal void ClearInfoTag(Transform anchor)
    {
        InfoTag infoTag = anchor.GetComponentInChildren <InfoTag>();

        if (infoTag != null)
        {
            infoTag.Hide();
        }
    }
Exemplo n.º 4
0
    protected override void OnEnable()
    {
        infoTag = GetComponentInChildren <InfoTag>();
        infoTag.gameObject.SetActive(false);

        transform.localScale = Vector3.zero;

        Invoke("StartScaling", this.delay);
    }
Exemplo n.º 5
0
    public void CreateInfoTag(Info content, Transform anchor)
    {
        InfoTag infoTag = Instantiate(infoTagPrefab).GetComponent <InfoTag>();

        infoTag.transform.SetParent(anchor, false);

        infoTag.gameObject.SetActive(true);

        infoTag.Show(content);
    }
Exemplo n.º 6
0
 public async Task <IActionResult> AddImage(IFormFile uploadFile, string info)
 {
     if (uploadFile != null)
     {
         Gallery gall = new Gallery();
         // путь к папке Files
         string path = "/db_data/Gallery/" + uploadFile.FileName + "-GImg.jpg";
         using (var fileStream = new FileStream(_appEnv.WebRootPath + path, FileMode.Create))
         {
             await uploadFile.CopyToAsync(fileStream);
         }
         if (info != null)
         {
             ICollection <InfoTag> tagList = new List <InfoTag>();
             string[] arr = info.Split("#");
             for (int i = 1; i < arr.Length; i++)
             {
                 var tag = new InfoTag
                 {
                     TagName = arr[i].ToLower()
                 };
                 tagList.Add(tag);
             }
             gall.InfoTags   = tagList;
             gall.Info       = info;
             gall.ImagePath  = path;
             gall.UploadDate = DateTime.Now;
             repositoryGall.SaveImage(gall);
             TempData["message"] = $"{uploadFile.FileName} has been saved";
             return(RedirectToAction("GalleryList"));
         }
         else
         {
             TempData["alert"] = "add some tags!";
             return(RedirectToAction("GalleryList"));
         }
     }
     else
     {
         TempData["alert"] = "choose image!";
         return(RedirectToAction("GalleryList"));
     }
 }
Exemplo n.º 7
0
 public IActionResult AddInfoTag(Gallery gall, string Tag)
 {
     if (ModelState.IsValid)
     {
         if (Tag != null)
         {
             ICollection <InfoTag> tagList = new List <InfoTag>();
             string[] arr = Tag.Split("#");
             for (int i = 1; i < arr.Length; i++)
             {
                 var cert = new InfoTag
                 {
                     TagName = arr[i]
                 };
                 tagList.Add(cert);
             }
             gall.InfoTags = tagList;
             repositoryGall.SaveImage(gall);
         }
     }
     return(RedirectToAction("GalleryList"));
 }
Exemplo n.º 8
0
 public IActionResult AddVideo(string videoPath, string info)
 {
     if (videoPath != null && info != null)
     {
         string tempUrl = videoPath.Remove(0, 17);
         tempUrl = tempUrl.Insert(0, "https://www.youtube.com/embed/");
         Gallery gall = new Gallery();
         ICollection <InfoTag> tagList = new List <InfoTag>();
         string[] arr = info.Split("#");
         for (int i = 1; i < arr.Length; i++)
         {
             var tag = new InfoTag
             {
                 TagName = arr[i].ToLower()
             };
             tagList.Add(tag);
         }
         gall.InfoTags   = tagList;
         gall.Info       = info;
         gall.ImagePath  = tempUrl;
         gall.UploadDate = DateTime.Now;
         repositoryGall.SaveImage(gall);
         TempData["message"] = $"{videoPath} has been saved";
         return(RedirectToAction("GalleryList"));
     }
     else
     {
         if (info == null)
         {
             TempData["alert"] = "add some tags!";
             return(RedirectToAction("GalleryList"));
         }
         TempData["alert"] = "add video url!";
         return(RedirectToAction("GalleryList"));
     }
 }
Exemplo n.º 9
0
        public ActionResult Create([Bind(Include = "Name,IsPlayerEnabled,SymbolFileName,BaseLocationId,AboutText,Blurb,Artist, IsSecret")] OrgCreateVM org,
                                   List <short> tags,
                                   HttpPostedFileBase picture,
                                   string submit)
        {
            #region Pre-model picture check
            if (picture != null)
            {
                string[] goodExts = { ".jpg", ".jpeg", ".gif", ".png" };
                string   imgName  = picture.FileName;

                string ext = imgName.Substring(imgName.LastIndexOf('.'));

                if (!goodExts.Contains(ext.ToLower()))
                {
                    ModelState.AddModelError("SymbolFileName", "You have submitted a incorrect file type for your portrait. Please use either: .jpg, .jpeg, .gif, or .png");
                }

                if (org.Artist == null)
                {
                    ModelState.AddModelError("Artist", "Katherine, you're trying to submit something with a picture without an artist. That's a no-no! But seriously, if something came up that means you need to change this rule, you know who to call.");
                }
            }
            #endregion

            org.IsPublished = false;
            if (ModelState.IsValid)
            {
                #region Info
                Info info;
                info = new Info
                {
                    InfoTypeId   = 3, //<-------------------Info Type ID. CHANGE UPON COPY
                    IdWithinType = null,
                    Blurb        = org.Blurb,
                    Name         = org.Name,
                    IsPublished  = org.IsPublished,
                    IsSecret     = org.IsSecret
                };
                db.Infos.Add(info);
                db.SaveChanges(); //this has to go here in order to ensure that the infoId short below is accurate. Also at this point I am doing no further gets on validity so there is no point to not saving
                #endregion
                short infoId = db.Infos.Max(i => i.InfoId);

                #region Adding Tags
                if (tags != null)
                {
                    foreach (short t in tags)
                    {
                        InfoTag infoTag = new InfoTag {
                            InfoId = infoId, TagId = t
                        };
                        db.InfoTags.Add(infoTag);
                    }
                }
                #endregion

                #region Image uploads
                string[] goodExts = { ".jpg", ".jpeg", ".gif", ".png" };
                org.SymbolFileName = "default.jpg";
                if (picture != null)
                {
                    string imgName = picture.FileName;

                    string ext = imgName.Substring(imgName.LastIndexOf('.'));

                    if (goodExts.Contains(ext.ToLower()))
                    {
                        imgName = "symbol-" + infoId.ToString() + ext;

                        picture.SaveAs(Server.MapPath("~/Content/img/org/" + imgName));
                    }
                    org.SymbolFileName = imgName;
                }
                #endregion

                #region Org
                Org daOrg = new Org
                {
                    InfoId          = infoId,
                    Name            = org.Name,
                    IsPlayerEnabled = org.IsPlayerEnabled,
                    SymbolFileName  = org.SymbolFileName,
                    BaseLocationId  = org.BaseLocationId,
                    AboutText       = org.AboutText,
                    IsPublished     = org.IsPublished,
                    Artist          = org.Artist
                };
                db.Orgs.Add(daOrg);
                db.SaveChanges();
                #endregion

                #region give info the IdWithinType
                short maxi = db.Orgs.Max(i => i.OrgId);
                info.IdWithinType    = maxi;
                db.Entry(info).State = EntityState.Modified;
                db.SaveChanges();
                #endregion

                return(RedirectToAction("AssoCreate", new { id = maxi, submit = submit }));
            }
            //if model not valid
            ViewBag.BaseLocationId = new SelectList(db.Locales.OrderBy(l => l.Name), "LocaleId", "Name");
            ViewBag.Tags           = new MultiSelectList(db.Tags, "TagId", "TagName", tags);

            if (picture != null)
            {
                ModelState.AddModelError("SymbolFileName", "Hey, there was some error, so you have to re-upload the picture");
            }
            ModelState.AddModelError("", "Something has gone wrong. Look for red text to see where is went wrong");

            return(View(org));
        }
Exemplo n.º 10
0
        public ActionResult Create([Bind(Include = "Name,TheContent, Blurb, IsSecret")] LoreCreateVM lore,
                                   List <short> tags,
                                   string submit)
        {
            #region Save or Publish?
            switch (submit)
            {
            case "Save Progress":
            case "Un-Publish":
                lore.IsPublished = false;
                break;

            case "Publish":
            case "Save":
                lore.IsPublished = true;
                break;
            }
            #endregion

            if (ModelState.IsValid)
            {
                #region Info
                Info info = new Info
                {
                    InfoTypeId   = 1, //<-------------------Info Type ID. CHANGE UPON COPY
                    IdWithinType = null,
                    Blurb        = lore.Blurb,
                    Name         = lore.Name,
                    IsPublished  = lore.IsPublished,
                    IsSecret     = lore.IsSecret
                };
                db.Infos.Add(info);
                db.SaveChanges(); //this has to go here in order to ensure that the infoId short below is accurate. Also at this point I am doing no further gets on validity so there is no point to not saving

                short infoId = db.Infos.Max(i => i.InfoId);

                #endregion

                #region Adding Tags
                if (tags != null)
                {
                    foreach (short t in tags)
                    {
                        InfoTag infoTag = new InfoTag {
                            InfoId = infoId, TagId = t
                        };
                        db.InfoTags.Add(infoTag);
                    }
                }
                #endregion

                #region Lore
                Lore daLore = new Lore
                {
                    InfoId      = infoId,
                    Name        = lore.Name,
                    TheContent  = lore.TheContent,
                    IsPublished = lore.IsPublished
                };
                db.Lores.Add(daLore);
                db.SaveChanges();
                #endregion

                #region give info the IdWithinType
                short maxi = db.Lores.Max(i => i.LoreId); // <------------ CHANGE THIS UPON COPY PASTE!!!!!!!!
                info.IdWithinType    = maxi;
                db.Entry(info).State = EntityState.Modified;
                db.SaveChanges();
                #endregion

                return(RedirectToAction("Details", new { id = maxi }));
            }

            //if model is not valid
            ViewBag.Tags = new MultiSelectList(db.Tags, "TagId", "TagName", tags);
            ModelState.AddModelError("", "Something has gone wrong. Look for red text to see where is went wrong");
            return(View(lore));
        }
Exemplo n.º 11
0
        public ActionResult Edit([Bind(Include = "EventId,InfoId,Name,IsHistory,AboutText,NormalParticipants,IsPublished,DateMonth,DateSeason, Blurb, IsSecret")] EventEditPostVM taevent,
                                 List <short> tags,
                                 string submit)
        {
            if (ModelState.IsValid)
            {
                #region Save or Publish?
                switch (submit)
                {
                case "Save Progress":
                case "Un-Publish":
                    taevent.IsPublished = false;
                    break;

                case "Publish":
                case "Save":
                    taevent.IsPublished = true;
                    break;

                case "Save and go to complex edit":
                    break;
                }
                #endregion

                var infoid = taevent.InfoId;
                #region Info Update
                //Info info = db.Infos.Find(infoid);
                Info info = db.Infos.Where(i => i.InfoId == infoid).FirstOrDefault();
                info.Name        = taevent.Name;
                info.Blurb       = taevent.Blurb;
                info.IsPublished = taevent.IsPublished;
                info.IsSecret    = taevent.IsSecret;
                #endregion

                #region Update tags
                List <short> currentTagIds = db.InfoTags.Where(x => x.InfoId == infoid).Select(x => x.TagId).ToList();

                if (tags != null)
                {
                    foreach (short tag in tags)
                    {
                        //if this is an already existing tag
                        if (currentTagIds.Contains(tag))
                        {
                            currentTagIds.Remove(tag);
                        }
                        //if this is a newly added tag
                        else
                        {
                            InfoTag newTag = new InfoTag {
                                InfoId = infoid, TagId = tag
                            };
                            db.InfoTags.Add(newTag);
                        }
                    }
                }

                if (currentTagIds.Count != 0)
                {
                    foreach (short id in currentTagIds)
                    {
                        InfoTag gone = db.InfoTags.Where(x => x.InfoId == infoid & x.TagId == id).FirstOrDefault();
                        db.InfoTags.Remove(gone);
                    }
                }

                #endregion

                #region Update Event
                Event daEvent = new Event
                {
                    InfoId             = taevent.InfoId,
                    EventId            = taevent.EventId,
                    Name               = taevent.Name,
                    IsHistory          = taevent.IsHistory,
                    AboutText          = taevent.AboutText,
                    NormalParticipants = taevent.NormalParticipants,
                    IsPublished        = taevent.IsPublished,
                    DateMonth          = taevent.DateMonth,
                    DateSeason         = taevent.DateSeason
                };
                db.Entry(daEvent).State = EntityState.Modified;
                db.Entry(info).State    = EntityState.Modified;
                db.SaveChanges();
                #endregion
                if (submit == "Save and go to complex edit")
                {
                    return(RedirectToAction("AssoEdit", new { id = taevent.EventId }));
                }
                return(RedirectToAction("Details", new { id = taevent.EventId }));
            }

            //if model invalid
            ViewBag.Tags = db.Tags.ToList();
            if (tags != null)
            {
                ViewBag.Selected = tags;
            }
            else
            {
                ViewBag.Selected = new List <short>();
            }
            ModelState.AddModelError("", "Something has gone wrong. Look for red text to see where is went wrong");
            EventEditVM aEvent = new EventEditVM(taevent);
            return(View(aEvent));
        }
Exemplo n.º 12
0
        public ActionResult Edit([Bind(Include = "LocaleId,InfoId,Name,LevelOfLocaleId,RegionId,ClosestCityId,CouncilDelegateId,Appointed,Environment,About,AvgLifestyle, Blurb, IsPublished, IsSecret")] LocaleEditPostVM locale,
                                 List <short> tags,
                                 string submit)
        {
            if (ModelState.IsValid)
            {
                #region Save or Publish?
                switch (submit)
                {
                case "Save Progress":
                case "Un-Publish":
                    locale.IsPublished = false;
                    break;

                case "Publish":
                case "Save":
                    locale.IsPublished = true;
                    break;

                case "Save and go to complex edit":
                    break;
                }
                #endregion

                var infoid = locale.InfoId;
                #region Info Update
                //Info info = db.Infos.Find(infoid);
                Info info = db.Infos.Where(i => i.InfoId == infoid).FirstOrDefault();
                info.Name        = locale.Name;
                info.Blurb       = locale.Blurb;
                info.IsPublished = locale.IsPublished;
                info.IsSecret    = locale.IsSecret;
                #endregion

                #region Update tags
                List <short> currentTagIds = db.InfoTags.Where(x => x.InfoId == infoid).Select(x => x.TagId).ToList();

                if (tags != null)
                {
                    foreach (short tag in tags)
                    {
                        //if this is an already existing tag
                        if (currentTagIds.Contains(tag))
                        {
                            currentTagIds.Remove(tag);
                        }
                        //if this is a newly added tag
                        else
                        {
                            InfoTag newTag = new InfoTag {
                                InfoId = infoid, TagId = tag
                            };
                            db.InfoTags.Add(newTag);
                        }
                    }
                }

                if (currentTagIds.Count != 0)
                {
                    foreach (short id in currentTagIds)
                    {
                        InfoTag gone = db.InfoTags.Where(x => x.InfoId == infoid & x.TagId == id).FirstOrDefault();
                        db.InfoTags.Remove(gone);
                    }
                }

                #endregion

                #region Update Locale
                Locale daLocale = new Locale
                {
                    InfoId            = locale.InfoId,
                    LocaleId          = locale.LocaleId,
                    Name              = locale.Name,
                    LevelOfLocaleId   = locale.LevelOfLocaleId,
                    RegionId          = locale.RegionId,
                    ClosestCityId     = locale.ClosestCityId,
                    CouncilDelegateId = locale.CouncilDelegateId,
                    Appointed         = locale.Appointed,
                    Environment       = locale.Environment,
                    About             = locale.About,
                    IsPublished       = locale.IsPublished,
                    AvgLifestyle      = locale.AvgLifestyle
                };
                db.Entry(daLocale).State = EntityState.Modified;
                db.Entry(info).State     = EntityState.Modified;
                db.SaveChanges();
                #endregion
                if (submit == "Save and go to complex edit")
                {
                    return(RedirectToAction("AssoEdit", new { id = locale.LocaleId }));
                }
                return(RedirectToAction("Details", new { id = locale.LocaleId }));
            }

            //if model invalid
            ViewBag.LevelOfLocaleId   = new SelectList(db.LocaleLevels, "LocaleLevelId", "LocaleName", locale.LevelOfLocaleId);
            ViewBag.RegionId          = new SelectList(db.Locales.OrderBy(l => l.Name), "LocaleId", "Name", locale.RegionId);
            ViewBag.ClosestCityId     = new SelectList(db.Locales.OrderBy(l => l.Name), "LocaleId", "Name", locale.ClosestCityId);
            ViewBag.CouncilDelegateId = new SelectList(db.NPCs.OrderBy(r => r.Name), "NpcId", "Name", locale.CouncilDelegateId);

            ViewBag.Tags = db.Tags.ToList();
            if (tags != null)
            {
                ViewBag.Selected = tags;
            }
            else
            {
                ViewBag.Selected = new List <short>();
            }
            ModelState.AddModelError("", "Something has gone wrong. Look for red text to see where is went wrong");
            LocaleEditVM aLocale = new LocaleEditVM(locale);
            return(View(aLocale));
        }
Exemplo n.º 13
0
        public ActionResult Edit([Bind(Include = "LoreId,InfoId,Name,TheContent,Blurb,IsPublished, IsSecret")] LoreEditVM lore,
                                 List <short> tags, string submit)
        {
            if (ModelState.IsValid)
            {
                #region Save or Publish?
                switch (submit)
                {
                case "Save Progress":
                case "Un-Publish":
                    lore.IsPublished = false;
                    break;

                case "Publish":
                case "Save":
                    lore.IsPublished = true;
                    break;
                }
                #endregion

                var infoid = lore.InfoId;
                #region Info Update
                //Info info = db.Infos.Find(infoid);
                Info info = db.Infos.Where(i => i.InfoId == infoid).FirstOrDefault();
                info.Name        = lore.Name;
                info.Blurb       = lore.Blurb;
                info.IsPublished = lore.IsPublished;
                info.IsSecret    = lore.IsSecret;
                #endregion

                #region Update tags
                List <short> currentTagIds = db.InfoTags.Where(x => x.InfoId == infoid).Select(x => x.TagId).ToList();

                if (tags != null)
                {
                    foreach (short tag in tags)
                    {
                        //if this is an already existing tag
                        if (currentTagIds.Contains(tag))
                        {
                            currentTagIds.Remove(tag);
                        }
                        //if this is a newly added tag
                        else
                        {
                            InfoTag newTag = new InfoTag {
                                InfoId = infoid, TagId = tag
                            };
                            db.InfoTags.Add(newTag);
                        }
                    }
                }

                if (currentTagIds.Count != 0)
                {
                    foreach (short id in currentTagIds)
                    {
                        InfoTag gone = db.InfoTags.Where(x => x.InfoId == infoid & x.TagId == id).FirstOrDefault();
                        db.InfoTags.Remove(gone);
                    }
                }

                #endregion

                #region Update Lore
                Lore daLore = new Lore
                {
                    LoreId      = lore.LoreId,
                    InfoId      = lore.InfoId,
                    Name        = lore.Name,
                    TheContent  = lore.TheContent,
                    IsPublished = lore.IsPublished
                };
                db.Entry(daLore).State = EntityState.Modified;
                db.SaveChanges();
                #endregion

                return(RedirectToAction("Details", new { id = lore.LoreId }));
            }

            ViewBag.Tags = db.Tags.ToList();
            if (tags != null)
            {
                ViewBag.Selected = tags;
            }
            else
            {
                ViewBag.Selected = new List <short>();
            }
            ModelState.AddModelError("", "Something has gone wrong. Look for red text to see where is went wrong");
            return(View(lore));
        }
Exemplo n.º 14
0
        public ActionResult Create([Bind(Include = "Name,LevelOfLocaleId,RegionId,ClosestCityId,CouncilDelegateId,Appointed,Environment,About, AvgLifestyle, Blurb, IsSecret")] LocaleCreateVM locale,
                                   List <short> tags,
                                   string submit)
        {
            //so this proves that the base submit can get the list of items on select. I'd have to figure out how to get the additional data while still not preventing the default of submit

            locale.IsPublished = false;
            //note the save/publish is intentionally NOT here in order to prevent posting it unintentionally
            if (ModelState.IsValid)
            {
                #region Info
                Info info;
                info = new Info
                {
                    InfoTypeId   = 4, //<-------------------Info Type ID. CHANGE UPON COPY
                    IdWithinType = null,
                    Blurb        = locale.Blurb,
                    Name         = locale.Name,
                    IsPublished  = locale.IsPublished,
                    IsSecret     = locale.IsSecret
                };
                db.Infos.Add(info);
                db.SaveChanges(); //this has to go here in order to ensure that the infoId short below is accurate. Also at this point I am doing no further gets on validity so there is no point to not saving
                #endregion
                short infoId = db.Infos.Max(i => i.InfoId);

                #region Adding Tags
                if (tags != null)
                {
                    foreach (short t in tags)
                    {
                        InfoTag infoTag = new InfoTag {
                            InfoId = infoId, TagId = t
                        };
                        db.InfoTags.Add(infoTag);
                    }
                }
                #endregion

                #region Locale
                Locale daLocale = new Locale
                {
                    InfoId            = infoId,
                    Name              = locale.Name,
                    LevelOfLocaleId   = locale.LevelOfLocaleId,
                    RegionId          = locale.RegionId,
                    ClosestCityId     = locale.ClosestCityId,
                    CouncilDelegateId = locale.CouncilDelegateId,
                    Appointed         = locale.Appointed,
                    Environment       = locale.Environment,
                    About             = locale.About,
                    IsPublished       = locale.IsPublished,
                    AvgLifestyle      = locale.AvgLifestyle
                };
                db.Locales.Add(daLocale);
                db.SaveChanges();
                #endregion

                #region give info the IdWithinType
                short maxi = db.Locales.Max(l => l.LocaleId);
                info.IdWithinType    = maxi;
                db.Entry(info).State = EntityState.Modified;
                db.SaveChanges();
                #endregion

                //move to step 2
                return(RedirectToAction("AssoCreate", new { id = maxi, submit = submit }));
            }

            //if model is not valid
            ViewBag.LevelOfLocaleId   = new SelectList(db.LocaleLevels, "LocaleLevelId", "LocaleName", locale.LevelOfLocaleId);
            ViewBag.RegionId          = new SelectList(db.Locales.Where(l => l.LevelOfLocaleId == 1).OrderBy(l => l.Name), "LocaleId", "Name", locale.RegionId);
            ViewBag.ClosestCityId     = new SelectList(db.Locales.Where(l => l.LevelOfLocaleId == 2).OrderBy(l => l.Name), "LocaleId", "Name", locale.ClosestCityId);
            ViewBag.CouncilDelegateId = new SelectList(db.NPCs.OrderBy(n => n.Name), "NpcId", "Name", locale.CouncilDelegateId);

            ViewBag.Tags = new MultiSelectList(db.Tags, "TagId", "TagName", tags);

            ModelState.AddModelError("", "Something has gone wrong. Look for red text to see where is went wrong");
            return(View(locale));
        }
Exemplo n.º 15
0
        public ActionResult Create([Bind(Include = "Name,Alias,Quote,PortraitFileName,RaceId,CrestFileName,ApperanceText,AboutText,LastLocationId,PortraitArtist,CrestArtist,IsDead,GenderId, Blurb, IsSecret")] NpcCreateVM npc,
                                   List <short> tags,
                                   HttpPostedFileBase portraitPic,
                                   HttpPostedFileBase crestPic,
                                   string submit)
        {
            #region Pre-model picture check
            if (portraitPic != null)
            {
                string[] goodExts = { ".jpg", ".jpeg", ".gif", ".png" };
                string   imgName  = portraitPic.FileName;

                string ext = imgName.Substring(imgName.LastIndexOf('.'));

                if (!goodExts.Contains(ext.ToLower()))
                {
                    ModelState.AddModelError("PortraitFileName", "You have submitted a incorrect file type for your portrait. Please use either: .jpg, .jpeg, .gif, or .png");
                }

                if (npc.PortraitArtist == null)
                {
                    ModelState.AddModelError("PortraitArtist", "Katherine, you're trying to submit something with a picture without an artist. That's a no-no! But seriously, if something came up that means you need to change this rule, you know who to call.");
                }
            }

            if (crestPic != null)
            {
                string[] goodExts = { ".jpg", ".jpeg", ".gif", ".png" };
                string   imgName  = crestPic.FileName;

                string ext = imgName.Substring(imgName.LastIndexOf('.'));

                if (!goodExts.Contains(ext.ToLower()))
                {
                    ModelState.AddModelError("CrestFileName", "You have submitted a incorrect file type for your portrait. Please use either: .jpg, .jpeg, .gif, or .png");
                }

                if (npc.CrestArtist == null)
                {
                    ModelState.AddModelError("CrestArtist", "Katherine, you're trying to submit something with a picture without an artist. That's a no-no! But seriously, if something came up that means you need to change this rule, you know who to call.");
                }
            }
            #endregion

            npc.IsPublished = false;
            if (ModelState.IsValid)
            {
                #region Info
                Info info;
                info = new Info
                {
                    InfoTypeId   = 2, //<-------------------Info Type ID. CHANGE UPON COPY
                    IdWithinType = null,
                    Blurb        = npc.Blurb,
                    Name         = npc.Name,
                    IsPublished  = npc.IsPublished,
                    IsSecret     = npc.IsSecret
                };
                db.Infos.Add(info);
                db.SaveChanges(); //this has to go here in order to ensure that the infoId short below is accurate. Also at this point I am doing no further gets on validity so there is no point to not saving
                #endregion
                short infoId = db.Infos.Max(i => i.InfoId);

                #region Adding Tags
                if (tags != null)
                {
                    foreach (short t in tags)
                    {
                        InfoTag infoTag = new InfoTag {
                            InfoId = infoId, TagId = t
                        };
                        db.InfoTags.Add(infoTag);
                    }
                }
                #endregion

                #region Image Uploads
                string[] goodExts = { ".jpg", ".jpeg", ".gif", ".png" };

                #region Image Upload -Portrait
                npc.PortraitFileName = "default.jpg";
                if (portraitPic != null)
                {
                    string imgName = portraitPic.FileName;

                    string ext = imgName.Substring(imgName.LastIndexOf('.'));

                    if (goodExts.Contains(ext.ToLower()))
                    {
                        imgName = "npc-portrait-" + infoId.ToString() + ext;
                        portraitPic.SaveAs(Server.MapPath("~/Content/img/npc/" + imgName));
                    }
                    npc.PortraitFileName = imgName;
                }
                #endregion

                #region Image Upload -Crest
                npc.CrestFileName = "org_default.jpg";
                if (crestPic != null)
                {
                    string imgName = crestPic.FileName;

                    string ext = imgName.Substring(imgName.LastIndexOf('.'));

                    if (goodExts.Contains(ext.ToLower()))
                    {
                        imgName = "npc-crest-" + infoId.ToString() + ext;

                        crestPic.SaveAs(Server.MapPath("~/Content/img/npc/" + imgName));
                    }
                    npc.CrestFileName = imgName;
                }
                #endregion

                #endregion

                #region NPC
                NPC daNpc = new NPC
                {
                    InfoId           = infoId,
                    Name             = npc.Name,
                    Alias            = npc.Alias,
                    Quote            = npc.Quote,
                    PortraitFileName = npc.PortraitFileName,
                    RaceId           = npc.RaceId,
                    CrestFileName    = npc.CrestFileName,
                    ApperanceText    = npc.ApperanceText,
                    AboutText        = npc.AboutText,
                    LastLocationId   = npc.LastLocationId,
                    IsPublished      = npc.IsPublished,
                    PortraitArtist   = npc.PortraitArtist,
                    CrestArtist      = npc.CrestArtist,
                    IsDead           = npc.IsDead,
                    GenderId         = npc.GenderId
                };
                db.NPCs.Add(daNpc);
                db.SaveChanges();
                #endregion

                #region give info the IdWithinType
                short maxi = db.NPCs.Max(i => i.NpcId);
                info.IdWithinType    = maxi;
                db.Entry(info).State = EntityState.Modified;
                db.SaveChanges();
                #endregion

                return(RedirectToAction("AssoCreate", new { id = maxi, submit = submit }));
            }

            #region model invalid
            ViewBag.LastLocationId = new SelectList(db.Locales.OrderBy(l => l.Name), "LocaleId", "Name");
            ViewBag.RaceId         = new SelectList(db.Races.OrderBy(r => r.RaceName), "RaceId", "RaceName");
            ViewBag.GenderId       = new SelectList(db.Genders, "GenderId", "GenderName", npc.GenderId);
            ViewBag.Tags           = new MultiSelectList(db.Tags, "TagId", "TagName", tags);

            if (portraitPic != null)
            {
                ModelState.AddModelError("PortraitFileName", "Hey, there was some error, so you have to re-upload the picture");
            }
            if (crestPic != null)
            {
                ModelState.AddModelError("CrestFileName", "Hey, there was some error, so you have to re-upload the picture");
            }
            ModelState.AddModelError("", "Something has gone wrong. Look for red text to see where is went wrong");

            #endregion
            return(View(npc));
        }
Exemplo n.º 16
0
        public ActionResult Create([Bind(Include = "Name,IsHistory,AboutText,NormalParticipants,DateMonth,DateSeason, Blurb, IsSecret")] EventCreateVM taevent,
                                   List <short> tags,
                                   string submit)
        {
            taevent.IsPublished = false;
            if (ModelState.IsValid)
            {
                #region Info
                Info info;
                info = new Info
                {
                    InfoTypeId   = 6, //<-------------------Info Type ID. CHANGE UPON COPY
                    IdWithinType = null,
                    Blurb        = taevent.Blurb,
                    Name         = taevent.Name,
                    IsPublished  = taevent.IsPublished,
                    IsSecret     = taevent.IsSecret
                };
                db.Infos.Add(info);
                db.SaveChanges(); //this has to go here in order to ensure that the infoId short below is accurate. Also at this point I am doing no further gets on validity so there is no point to not saving
                #endregion
                short infoId = db.Infos.Max(i => i.InfoId);

                #region Adding Tags
                if (tags != null)
                {
                    foreach (short t in tags)
                    {
                        InfoTag infoTag = new InfoTag {
                            InfoId = infoId, TagId = t
                        };
                        db.InfoTags.Add(infoTag);
                    }
                }
                #endregion

                #region Event
                Event daEvent = new Event
                {
                    InfoId             = infoId,
                    Name               = taevent.Name,
                    IsHistory          = taevent.IsHistory,
                    AboutText          = taevent.AboutText,
                    NormalParticipants = taevent.NormalParticipants,
                    IsPublished        = taevent.IsPublished,
                    DateMonth          = taevent.DateMonth,
                    DateSeason         = taevent.DateSeason
                };
                db.Events.Add(daEvent);
                db.SaveChanges();
                #endregion

                #region give info the IdWithinType
                short maxi = db.Events.Max(l => l.EventId);
                info.IdWithinType    = maxi;
                db.Entry(info).State = EntityState.Modified;
                db.SaveChanges();
                #endregion

                //move to step 2
                return(RedirectToAction("AssoCreate", new { id = maxi, submit = submit }));
            }

            //if model is not valid
            ViewBag.Tags = new MultiSelectList(db.Tags, "TagId", "TagName", tags);

            ModelState.AddModelError("", "Something has gone wrong. Look for red text to see where is went wrong");
            return(View(taevent));
        }
Exemplo n.º 17
0
        public ActionResult Edit([Bind(Include = "ItemId,InfoId,Name,Blurb,PictureFileName,DescriptionText,PropertyText,HistoryText, Artist, IsPublished, IsSecret")] ItemEditPostVM item,
                                 HttpPostedFileBase picture,
                                 List <short> tags, string submit)
        {
            #region Pre-model picture check
            if (picture != null)
            {
                string[] goodExts = { ".jpg", ".jpeg", ".gif", ".png" };
                string   imgName  = picture.FileName;

                var    length = picture.ContentLength;
                string ext    = imgName.Substring(imgName.LastIndexOf('.'));

                if (!goodExts.Contains(ext.ToLower()))
                {
                    ModelState.AddModelError("PictureFileName", "You have submitted a incorrect file type for your portrait. Please use either: .jpg, .jpeg, .gif, or .png");
                }

                if (item.Artist == null)
                {
                    ModelState.AddModelError("Artist", "Katherine, you're trying to submit something with a picture without an artist. That's a no-no! But seriously, if something came up that means you need to change this rule, you know who to call.");
                }
            }
            else if (item.PictureFileName != "default.jpg" && item.Artist == null)
            {
                ModelState.AddModelError("Artist", "Yo bud, you tired? Seems you deleted the artist by accident. Why don't ya fix that?");
            }
            #endregion

            if (ModelState.IsValid)
            {
                #region Save or Publish?
                switch (submit)
                {
                case "Save Progress":
                case "Un-Publish":
                    item.IsPublished = false;
                    break;

                case "Publish":
                case "Save":
                    item.IsPublished = true;
                    break;
                }
                #endregion

                var infoid = item.InfoId;
                #region Info Update
                //Info info = db.Infos.Find(infoid);
                Info info = db.Infos.Where(i => i.InfoId == infoid).FirstOrDefault();
                info.Name        = item.Name;
                info.Blurb       = item.Blurb;
                info.IsPublished = item.IsPublished;
                info.IsSecret    = item.IsSecret;
                #endregion

                #region Update tags
                List <short> currentTagIds = db.InfoTags.Where(x => x.InfoId == infoid).Select(x => x.TagId).ToList();

                if (tags != null)
                {
                    foreach (short tag in tags)
                    {
                        //if this is an already existing tag
                        if (currentTagIds.Contains(tag))
                        {
                            currentTagIds.Remove(tag);
                        }
                        //if this is a newly added tag
                        else
                        {
                            InfoTag newTag = new InfoTag {
                                InfoId = infoid, TagId = tag
                            };
                            db.InfoTags.Add(newTag);
                        }
                    }
                }

                if (currentTagIds.Count != 0)
                {
                    foreach (short id in currentTagIds)
                    {
                        InfoTag gone = db.InfoTags.Where(x => x.InfoId == infoid & x.TagId == id).FirstOrDefault();
                        db.InfoTags.Remove(gone);
                    }
                }

                #endregion


                #region Image update/upload
                string[] goodExts = { ".jpg", ".jpeg", ".gif", ".png" };

                #region Image Upload - picture
                if (picture != null)
                {
                    string imgName = picture.FileName;

                    string ext = imgName.Substring(imgName.LastIndexOf('.'));

                    if (goodExts.Contains(ext.ToLower()))
                    {
                        imgName = "item-" + infoid + ext;

                        picture.SaveAs(Server.MapPath("~/Content/img/item/" + imgName));
                    }
                    //remove old picture if it had a different extension (and thus would not be overridden)
                    string oldName = item.PictureFileName;
                    string oldExt  = oldName.Substring(oldName.LastIndexOf('.'));
                    if (oldName != "default.jpg" && oldExt != ext)
                    {
                        string fullPath = Request.MapPath("~/Content/img/item/" + oldName);
                        if (System.IO.File.Exists(fullPath))
                        {
                            System.IO.File.Delete(fullPath);
                        }
                    }
                    //assign new PictureFileName
                    item.PictureFileName = imgName;
                }
                #endregion
                #endregion

                #region Update Item
                Item daItem = new Item
                {
                    ItemId          = item.ItemId,
                    InfoId          = item.InfoId,
                    Name            = item.Name,
                    PictureFileName = item.PictureFileName,
                    DescriptionText = item.DescriptionText,
                    PropertyText    = item.PropertyText,
                    HistoryText     = item.HistoryText,
                    IsPublished     = item.IsPublished,
                    Artist          = item.Artist
                };
                db.Entry(daItem).State = EntityState.Modified;
                db.Entry(info).State   = EntityState.Modified;
                db.SaveChanges();
                #endregion

                return(RedirectToAction("Details", new { id = item.ItemId }));
            }

            ViewBag.Tags = db.Tags.ToList();
            if (tags != null)
            {
                ViewBag.Selected = tags;
            }
            else
            {
                ViewBag.Selected = new List <short>();
            }
            if (picture != null)
            {
                ModelState.AddModelError("PictureFileName", "Hey, there was some error, so you have to re-upload the picture");
            }
            ModelState.AddModelError("", "Something has gone wrong. Look for red text to see where is went wrong");
            ItemEditVM aItem = new ItemEditVM(item);
            return(View(aItem));
        }
Exemplo n.º 18
0
        public ActionResult Edit([Bind(Include = "NpcId,InfoId,Name,Alias,Quote,PortraitFileName,RaceId,CrestFileName,ApperanceText,AboutText,LastLocationId,PortraitArtist,CrestArtist,IsDead,GenderId, Blurb, IsSecret")] NpcEditPostVM npc,
                                 List <short> tags,
                                 HttpPostedFileBase portraitPic,
                                 HttpPostedFileBase crestPic,
                                 string submit)
        {
            #region Pre-model picture check
            if (portraitPic != null)
            {
                string[] goodExts = { ".jpg", ".jpeg", ".gif", ".png" };
                string   imgName  = portraitPic.FileName;

                string ext = imgName.Substring(imgName.LastIndexOf('.'));

                if (!goodExts.Contains(ext.ToLower()))
                {
                    ModelState.AddModelError("PortraitFileName", "You have submitted a incorrect file type for your portrait. Please use either: .jpg, .jpeg, .gif, or .png");
                }

                if (npc.PortraitArtist == null)
                {
                    ModelState.AddModelError("PortraitArtist", "Katherine, you're trying to submit something with a picture without an artist. That's a no-no! But seriously, if something came up that means you need to change this rule, you know who to call.");
                }
            }
            else if ((npc.PortraitFileName != "default.jpg" && npc.PortraitFileName != null) && npc.PortraitArtist == null)
            {
                ModelState.AddModelError("PortraitArtist", "Yo bud, you tired? Seems you deleted the artist by accident. Why don't ya fix that?");
            }

            if (crestPic != null)
            {
                string[] goodExts = { ".jpg", ".jpeg", ".gif", ".png" };
                string   imgName  = crestPic.FileName;

                string ext = imgName.Substring(imgName.LastIndexOf('.'));

                if (!goodExts.Contains(ext.ToLower()))
                {
                    ModelState.AddModelError("CrestFileName", "You have submitted a incorrect file type for your portrait. Please use either: .jpg, .jpeg, .gif, or .png");
                }

                if (npc.CrestArtist == null)
                {
                    ModelState.AddModelError("CrestArtist", "Katherine, you're trying to submit something with a picture without an artist. That's a no-no! But seriously, if something came up that means you need to change this rule, you know who to call.");
                }
            }
            else if ((npc.CrestFileName != "org_default.jpg" && npc.CrestFileName != null) && npc.CrestArtist == null)
            {
                ModelState.AddModelError("CrestArtist", "Yo bud, you tired? Seems you deleted the artist by accident. Why don't ya fix that?");
            }
            #endregion

            if (ModelState.IsValid)
            {
                #region Save or Publish?
                switch (submit)
                {
                case "Save Progress":
                case "Un-Publish":
                    npc.IsPublished = false;
                    break;

                case "Publish":
                case "Save":
                    npc.IsPublished = true;
                    break;

                case "Save and go to complex edit":
                    break;
                }
                #endregion

                var infoid = npc.InfoId;
                #region Info Update
                //Info info = db.Infos.Find(infoid);
                Info info = db.Infos.Where(i => i.InfoId == infoid).FirstOrDefault();
                info.Name        = npc.Name;
                info.Blurb       = npc.Blurb;
                info.IsPublished = npc.IsPublished;
                info.IsSecret    = npc.IsSecret;
                #endregion

                #region Update tags
                List <short> currentTagIds = db.InfoTags.Where(x => x.InfoId == infoid).Select(x => x.TagId).ToList();

                if (tags != null)
                {
                    foreach (short tag in tags)
                    {
                        //if this is an already existing tag
                        if (currentTagIds.Contains(tag))
                        {
                            currentTagIds.Remove(tag);
                        }
                        //if this is a newly added tag
                        else
                        {
                            InfoTag newTag = new InfoTag {
                                InfoId = infoid, TagId = tag
                            };
                            db.InfoTags.Add(newTag);
                        }
                    }
                }

                if (currentTagIds.Count != 0)
                {
                    foreach (short id in currentTagIds)
                    {
                        InfoTag gone = db.InfoTags.Where(x => x.InfoId == infoid & x.TagId == id).FirstOrDefault();
                        db.InfoTags.Remove(gone);
                    }
                }

                #endregion

                #region Image Update/Upload
                string[] goodExts = { ".jpg", ".jpeg", ".gif", ".png" };

                #region Image Update -Portrait
                if (portraitPic != null)
                {
                    string imgName = portraitPic.FileName;

                    string ext = imgName.Substring(imgName.LastIndexOf('.'));

                    if (goodExts.Contains(ext.ToLower()))
                    {
                        imgName = "npc-portrait-" + infoid.ToString() + ext;
                        portraitPic.SaveAs(Server.MapPath("~/Content/img/npc/" + imgName));
                    }
                    //remove old picture if it had a different extension (and thus would not be overridden)
                    string oldName = npc.PortraitFileName;
                    string oldExt  = oldName.Substring(oldName.LastIndexOf('.'));
                    if (oldName != "default.jpg" && oldExt != ext)
                    {
                        string fullPath = Request.MapPath("~/Content/img/npc/" + oldName);
                        if (System.IO.File.Exists(fullPath))
                        {
                            System.IO.File.Delete(fullPath);
                        }
                    }
                    //assign new PortraitFileName
                    npc.PortraitFileName = imgName;
                }
                #endregion

                #region Image Update -Crest
                if (crestPic != null)
                {
                    string imgName = crestPic.FileName;

                    string ext = imgName.Substring(imgName.LastIndexOf('.'));

                    if (goodExts.Contains(ext.ToLower()))
                    {
                        imgName = "npc-crest-" + infoid.ToString() + ext;

                        crestPic.SaveAs(Server.MapPath("~/Content/img/npc/" + imgName));
                    }
                    //remove old picture if it had a different extension (and thus would not be overridden)
                    string oldName = npc.CrestFileName;
                    string oldExt  = oldName.Substring(oldName.LastIndexOf('.'));
                    if (oldName != "org_default.jpg" && oldExt != ext)
                    {
                        string fullPath = Request.MapPath("~/Content/img/npc/" + oldName);
                        if (System.IO.File.Exists(fullPath))
                        {
                            System.IO.File.Delete(fullPath);
                        }
                    }
                    //assign new CrestFileName
                    npc.CrestFileName = imgName;
                }
                #endregion

                #endregion

                #region Update Npc
                NPC daNpc = new NPC
                {
                    NpcId            = npc.NpcId,
                    InfoId           = npc.InfoId,
                    Name             = npc.Name,
                    Alias            = npc.Alias,
                    Quote            = npc.Quote,
                    PortraitFileName = npc.PortraitFileName,
                    RaceId           = npc.RaceId,
                    CrestFileName    = npc.CrestFileName,
                    ApperanceText    = npc.ApperanceText,
                    AboutText        = npc.AboutText,
                    LastLocationId   = npc.LastLocationId,
                    IsPublished      = npc.IsPublished,
                    PortraitArtist   = npc.PortraitArtist,
                    CrestArtist      = npc.CrestArtist,
                    IsDead           = npc.IsDead,
                    GenderId         = npc.GenderId
                };
                db.Entry(daNpc).State = EntityState.Modified;
                db.Entry(info).State  = EntityState.Modified;
                db.SaveChanges();
                #endregion
                if (submit == "Save and go to complex edit")
                {
                    return(RedirectToAction("AssoEdit", new { id = npc.NpcId }));
                }
                return(RedirectToAction("Details", new { id = npc.NpcId }));
            }

            #region if model invalid
            ViewBag.LastLocationId = new SelectList(db.Locales, "LocaleId", "Name", npc.LastLocationId);
            ViewBag.RaceId         = new SelectList(db.Races, "RaceId", "RaceName", npc.RaceId);
            ViewBag.GenderId       = new SelectList(db.Genders, "GenderId", "GenderName", npc.GenderId);
            ViewBag.Tags           = db.Tags.ToList();
            if (tags != null)
            {
                ViewBag.Selected = tags;
            }
            else
            {
                ViewBag.Selected = new List <short>();
            }

            if (portraitPic != null)
            {
                ModelState.AddModelError("PortraitFileName", "Hey, there was some error, so you have to re-upload the picture");
            }
            if (crestPic != null)
            {
                ModelState.AddModelError("CrestFileName", "Hey, there was some error, so you have to re-upload the picture");
            }
            ModelState.AddModelError("", "Something has gone wrong. Look for red text to see where is went wrong");
            #endregion

            NpcEditVM aNpc = new NpcEditVM(npc);
            return(View(aNpc));
        }
Exemplo n.º 19
0
        public ActionResult Create([Bind(Include = "Name,Blurb,PictureFileName,DescriptionText,PropertyText,HistoryText, Artist, IsSecret")] ItemCreateVM item,
                                   HttpPostedFileBase picture,
                                   List <short> tags,
                                   string submit)
        {
            //so it seems that - at least for none complicated associations like tags - I am actually able to just use the base submit

            //extra logic here for when I allow the empty placeholders during save actions. Check if the action is save and then stop her if it isn't
            #region Save or Publish?
            switch (submit)
            {
            case "Save Progress":
            case "Un-Publish":
                item.IsPublished = false;
                break;

            case "Publish":
            case "Save":
                item.IsPublished = true;
                break;
            }
            #endregion

            #region Pre-model picture check
            if (picture != null)
            {
                string[] goodExts = { ".jpg", ".jpeg", ".gif", ".png" };
                string   imgName  = picture.FileName;

                var    length = picture.ContentLength;
                string ext    = imgName.Substring(imgName.LastIndexOf('.'));

                if (!goodExts.Contains(ext.ToLower()))
                {
                    ModelState.AddModelError("PictureFileName", "You have submitted a incorrect file type for your portrait. Please use either: .jpg, .jpeg, .gif, or .png");
                }

                if (item.Artist == null)
                {
                    ModelState.AddModelError("Artist", "Katherine, you're trying to submit something with a picture without an artist. That's a no-no! But seriously, if something came up that means you need to change this rule, you know who to call.");
                }
            }
            #endregion

            if (ModelState.IsValid)
            {
                #region Info

                Info info = new Info
                {
                    InfoTypeId   = 7, //<-------------------Info Type ID. CHANGE UPON COPY
                    IdWithinType = null,
                    Blurb        = item.Blurb,
                    Name         = item.Name,
                    IsPublished  = item.IsPublished,
                    IsSecret     = item.IsSecret
                };
                db.Infos.Add(info);
                db.SaveChanges(); //this has to go here in order to ensure that the infoId short below is accurate. Also at this point I am doing no further gets on validity so there is no point to not saving
                #endregion

                short infoId = db.Infos.Max(i => i.InfoId);

                #region Adding Tags
                if (tags != null)
                {
                    foreach (short t in tags)
                    {
                        InfoTag infoTag = new InfoTag {
                            InfoId = infoId, TagId = t
                        };
                        db.InfoTags.Add(infoTag);
                    }
                }
                #endregion

                #region Image uploads
                string[] goodExts = { ".jpg", ".jpeg", ".gif", ".png" };
                item.PictureFileName = "default.jpg";
                if (picture != null)
                {
                    string imgName = picture.FileName;

                    string ext = imgName.Substring(imgName.LastIndexOf('.'));

                    if (goodExts.Contains(ext.ToLower()))
                    {
                        imgName = "item-" + infoId.ToString() + ext;

                        picture.SaveAs(Server.MapPath("~/Content/img/item/" + imgName));
                    }
                    item.PictureFileName = imgName;
                }
                #endregion

                #region Item
                Item daItem = new Item
                {
                    InfoId          = infoId,
                    Name            = item.Name,
                    PictureFileName = item.PictureFileName,
                    DescriptionText = item.DescriptionText,
                    PropertyText    = item.PropertyText,
                    HistoryText     = item.HistoryText,
                    IsPublished     = item.IsPublished,
                    Artist          = item.Artist
                };
                db.Items.Add(daItem);
                db.SaveChanges();
                #endregion

                //now give the info the idWithinType
                #region give info the IdWithinType
                short maxi = db.Items.Max(i => i.ItemId);
                info.IdWithinType    = maxi;
                db.Entry(info).State = EntityState.Modified;
                db.SaveChanges();
                #endregion

                return(RedirectToAction("Details", new { id = maxi }));
            }

            //if model is not valid
            ViewBag.Tags = new MultiSelectList(db.Tags, "TagId", "TagName", tags);

            if (picture != null)
            {
                ModelState.AddModelError("PictureFileName", "Hey, there was some error, so you have to re-upload the picture");
            }
            ModelState.AddModelError("", "Something has gone wrong. Look for red text to see where is went wrong");
            return(View(item));
        }
Exemplo n.º 20
0
        public ActionResult Create([Bind(Include = "Nickname,Location,Environment,Hazards,Blurb, IsSecret")] RiftCreateVM rift,
                                   List <short> tags,
                                   string submit)
        {
            rift.IsPublished = false;
            if (ModelState.IsValid)
            {
                #region Info
                Info info;
                info = new Info
                {
                    InfoTypeId   = 5, //<-------------------Info Type ID. CHANGE UPON COPY
                    IdWithinType = null,
                    Blurb        = rift.Blurb,
                    Name         = rift.Nickname,
                    IsPublished  = rift.IsPublished,
                    IsSecret     = rift.IsSecret
                };
                db.Infos.Add(info);
                db.SaveChanges(); //this has to go here in order to ensure that the infoId short below is accurate. Also at this point I am doing no further gets on validity so there is no point to not saving
                #endregion
                short infoId = db.Infos.Max(i => i.InfoId);

                #region Adding Tags
                if (tags != null)
                {
                    foreach (short t in tags)
                    {
                        InfoTag infoTag = new InfoTag {
                            InfoId = infoId, TagId = t
                        };
                        db.InfoTags.Add(infoTag);
                    }
                }
                #endregion

                #region Rift
                Rift daRift = new Rift
                {
                    InfoId      = infoId,
                    Nickname    = rift.Nickname,
                    Location    = rift.Location,
                    Environment = rift.Environment,
                    Hazards     = rift.Hazards,
                    IsPublished = rift.IsPublished
                };
                db.Rifts.Add(daRift);
                db.SaveChanges();
                #endregion

                #region give info the IdWithinType
                short riftId = db.Rifts.Max(l => l.RiftId);
                info.IdWithinType    = riftId;
                db.Entry(info).State = EntityState.Modified;
                db.SaveChanges();
                #endregion

                return(RedirectToAction("AssoCreate", new { id = riftId, submit = submit }));
            }

            ViewBag.Tags = new MultiSelectList(db.Tags, "TagId", "TagName", tags);

            ModelState.AddModelError("", "Something has gone wrong. Look for red text to see where is went wrong");
            return(View(rift));
        }