Beispiel #1
0
        public IActionResult PostInitiativeForm(InitiativeModel initiativeModel)
        {
            var initiative = new Initiative
            {
                InitiativeName    = initiativeModel.Name,
                InitiativeAddress = initiativeModel.InitiativeAddress,
                InitiativeId      = 0,
                work          = initiativeModel.work,
                team          = initiativeModel.team,
                facebookLink  = initiativeModel.facebookLink,
                instagramLink = initiativeModel.instagramLink,
                phoneNumber   = initiativeModel.phoneNumber,
                websiteLink   = initiativeModel.websiteLink
            };
            var uploadedImage = initiativeModel.imageUpload;

            if (uploadedImage != null && uploadedImage.ContentType.ToLower().StartsWith("image/"))
            {
                //    var root = he.WebRootPath;
                //    root = root + "\\SubmittedInitiativeImg";
                ////same file name problems
                //var filename = Path.Combine(he.WebRootPath, Path.GetFileName(uploadedImage.FileName));
                var name     = Guid.NewGuid() + Path.GetFileName(uploadedImage.FileName);
                var filename = Path.Combine(he.WebRootPath, name);

                uploadedImage.CopyTo(new FileStream(filename, FileMode.Create));
                initiative.filepath = "/" + name;
            }

            initiative.UserId = _usermgr.GetUserId(HttpContext.User);
            initiative.User   = _dbContext.AppUsers.Find(_usermgr.GetUserId(HttpContext.User));

            //{
            //    MemoryStream ms = new MemoryStream();
            //    uploadedImage.OpenReadStream().CopyTo(ms);
            //    System.Drawing.Image image = System.Drawing.Image.FromStream(ms);
            //    Infrastructure.Image imageEntity = new Infrastructure.Image();
            //    imageEntity.Name = uploadedImage.Name;
            //    imageEntity.Data = ms.ToArray();
            //    imageEntity.Width = image.Width;
            //    imageEntity.Height = image.Height;
            //    imageEntity.ContentType = uploadedImage.ContentType;
            //    initiative.Image = imageEntity;

            //}

            initiative.categoryId = initiativeModel.categoryId;
            initiative.Category   = CategoryDict.Categories[initiative.categoryId];
            initiative.Visible    = false;
            _dbContext.Add(initiative);
            _dbContext.SaveChanges();
            return(Redirect(initiativeModel.returnUrl ?? "/Initiatives/Index"));
        }
Beispiel #2
0
        public ActionResult Initiative(Guid initiativeId)
        {
            var provider = new InitiativeProvider();

            var intiative  = provider.Get(initiativeId);
            var challenges = provider.GetAllChallenges(initiativeId);

            if (intiative == null)
            {
                return(View(new InitiativeModel()));
            }

            var model = new InitiativeModel
            {
                Id          = intiative.Id,
                Title       = intiative.Title,
                Description = intiative.Description,
                Challenges  = challenges
            };

            return(View(model));
        }