Beispiel #1
0
        public ActionResult PersonPartialCreate(string subplatform, PersonEditModel personEditModel)
        {
            byte[] image = null;
            if (ModelState.IsValid)
            {
                Subplatform  Subplatform  = SubplatformMgr.GetSubplatform(subplatform);
                Organisation organisation = null;
                if (personEditModel.OrganisationId != null && personEditModel.OrganisationId >= 1)
                {
                    organisation = itemMgr.GetOrganisation((int)personEditModel.OrganisationId);
                    if (organisation == null)
                    {
                        return(RedirectToAction("ItemBeheer", "Item"));
                    }
                }
                var    iconUrl   = "";
                string _FileName = "";
                if (personEditModel.file != null)
                {
                    if (personEditModel.file.ContentLength > 0)
                    {
                        //_FileName = Path.GetFileName(personEditModel.file.FileName);
                        //var username = personEditModel.Name.ToString();
                        //var newName = username + "." + _FileName.Substring(_FileName.IndexOf(".") + 1);
                        //string _path = Path.Combine(Server.MapPath("~/Content/Images/Persons/"), newName);
                        //personEditModel.file.SaveAs(_path);
                        //iconUrl = @"~/Content/Images/Persons/" + newName;
                        ImageConverter imgCon = new ImageConverter();
                        var            img    = Image.FromStream(personEditModel.file.InputStream);
                        image = (byte[])imgCon.ConvertTo(img, typeof(byte[]));
                    }
                }
                else
                {
                    iconUrl = Subplatform.Settings.Where(p => p.SettingName.Equals(Setting.Platform.DEFAULT_NEW_ITEM_ICON)).First().Value;
                }

                itemMgr.AddPerson(personEditModel.Name, personEditModel.SocialMediaLink, iconUrl, personEditModel.IsTrending, null, null, null, null, null, null, null, personEditModel.Gemeente, null, null, organisation, Subplatform, null, image);

                return(RedirectToAction("ItemBeheer", "Item"));
            }
            return(RedirectToAction("ItemBeheer", "Item"));
        }