public IHttpActionResult ListEventsForNonProfit(string nonprofitid)
        {
            var db = new ApplicationDbContext();

            NonProfit nonProfit = db.NonProfits.Find(nonprofitid);

            if (nonProfit == null)
            {
                return(NotFound());
            }

            var eventList = new
            {
                nonProfitId     = nonProfit.Id,
                nonProfitName   = nonProfit.Name,
                nonProfitURL    = nonProfit.WebsiteURL,
                nonProfitActive = nonProfit.Active,
                //Events = nonProfit.Events
                Events = nonProfit.Events.Select(thisEvent =>
                                                 new {
                    thisEvent.EventId,
                    thisEvent.EventName,
                    //thisEvent.StartDate,
                    //thisEvent.EndDate,
                    StartDate = thisEvent.StartDate.ToLocalTime().ToString("MM/dd/yyyy @h:mm tt"),
                    EndDate   = thisEvent.EndDate.ToLocalTime().ToString("MM/dd/yyyy @h:mm tt"),
                    thisEvent.Description
                })
            };

            return(Ok(eventList));
            //return Ok(nonProfit.Events);
        }
Exemplo n.º 2
0
        public ActionResult Edit(int id)
        {
            NonProfit thisNonProfit = _db.NonProfits.FirstOrDefault(NonProfit => NonProfit.NonProfitId == id);

            ViewBag.NonProfitId = new SelectList(_db.NonProfits, "NonProfitId", "Name");
            return(View(thisNonProfit));
        }
        public IHttpActionResult PostNonProfit(NonProfit nonProfit)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Users.Add(nonProfit);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (NonProfitExists(nonProfit.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = nonProfit.Id }, nonProfit));
        }
Exemplo n.º 4
0
        public void Update(NonProfit nonProfit)
        {
            using (var conn = Connection)
            {
                conn.Open();
                using (var cmd = conn.CreateCommand())
                {
                    cmd.CommandText = @"
                        UPDATE NonProfit
                           SET OwnerId = OwnerId,
                               Name = @Name,
                               Location = @Location,
                               Cause = @Cause,
                               Description = @Description,
                               MissionStatement = @MissionStatement,
                               Website = @Website
                         WHERE Id = @Id";

                    DbUtils.AddParameter(cmd, "@Name", nonProfit.Name);
                    DbUtils.AddParameter(cmd, "@Location", nonProfit.Location);
                    DbUtils.AddParameter(cmd, "@Cause", nonProfit.Cause);
                    DbUtils.AddParameter(cmd, "@Description", nonProfit.Description);
                    DbUtils.AddParameter(cmd, "@MissionStatement", nonProfit.MissionStatement);
                    DbUtils.AddParameter(cmd, "@Website", nonProfit.Website);
                    DbUtils.AddParameter(cmd, "@Id", nonProfit.Id);

                    cmd.ExecuteNonQuery();
                }
            }
        }
Exemplo n.º 5
0
        public void Add(NonProfit nonProfit)
        {
            using (var conn = Connection)
            {
                conn.Open();
                using (var cmd = conn.CreateCommand())
                {
                    cmd.CommandText = @"
                        INSERT INTO NonProfit (OwnerId, Name, Location, Cause, 
                                          Description, MissionStatement, Website)
                        OUTPUT INSERTED.ID
                        VALUES (@OwnerId, @Name, @Location, @Cause, @Description,
                                 @MissionStatement, @Website)";

                    DbUtils.AddParameter(cmd, "@OwnerId", nonProfit.OwnerId);
                    DbUtils.AddParameter(cmd, "@Name", nonProfit.Name);
                    DbUtils.AddParameter(cmd, "@Location", nonProfit.Location);
                    DbUtils.AddParameter(cmd, "@Cause", nonProfit.Cause);
                    DbUtils.AddParameter(cmd, "@Description", nonProfit.Description);
                    DbUtils.AddParameter(cmd, "@MissionStatement", nonProfit.MissionStatement);
                    DbUtils.AddParameter(cmd, "@Website", nonProfit.Website);

                    nonProfit.Id = (int)cmd.ExecuteScalar();
                }
            }
        }
Exemplo n.º 6
0
        public IActionResult Post(NonProfit NonProfit)
        {
            var currentUserProfile = GetCurrentUserProfile();

            NonProfit.OwnerId = currentUserProfile.Id;
            _nonProfitRepository.Add(NonProfit);
            return(CreatedAtAction("Get", new { id = NonProfit.Id }, NonProfit));
        }
Exemplo n.º 7
0
        public ActionResult DeleteConfirmed(int id)
        {
            NonProfit thisNonProfit = _db.NonProfits.FirstOrDefault(nonProfit => nonProfit.NonProfitId == id);

            _db.NonProfits.Remove(thisNonProfit);
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        //public IQueryable<NonProfit> GetUsers()
        public IHttpActionResult GetCurrentNonProfit()
        {
            NonProfit nonProfit = db.NonProfits.Find(User.Identity.GetUserId());

            if (nonProfit == null)
            {
                return(NotFound());
            }

            return(Ok(nonProfit));
        }
        public IHttpActionResult GetNonProfitById(string id)
        {
            NonProfit nonProfit = db.NonProfits.Find(id);

            if (nonProfit == null)
            {
                return(NotFound());
            }

            return(Ok(nonProfit));
        }
        public IHttpActionResult DeleteNonProfit(string id)
        {
            NonProfit nonProfit = db.NonProfits.Find(id);

            if (nonProfit == null)
            {
                return(NotFound());
            }

            db.Users.Remove(nonProfit);
            db.SaveChanges();

            return(Ok(nonProfit));
        }
Exemplo n.º 11
0
        public IActionResult Put(int Id, NonProfit nonProfit)
        {
            var currentUserProfile = GetCurrentUserProfile();
            var NonProfitFromDB    = _nonProfitRepository.GetNonProfitById(Id);

            if (NonProfitFromDB.OwnerId == currentUserProfile.Id)
            {
                _nonProfitRepository.Update(nonProfit);
                return(Ok());
            }
            else
            {
                return(Unauthorized());
            }
        }
Exemplo n.º 12
0
        public NonProfit GetNonProfitById(int id)
        {
            using (var conn = Connection)
            {
                conn.Open();
                using (var cmd = conn.CreateCommand())
                {
                    cmd.CommandText = @"
                            SELECT n.Id, n.OwnerId, n.Name, n.Location, n.Cause, n.Description, n.MissionStatement,
                                   n.website, up.FirstName, up.LastName, up.DisplayName, up.Email
                            FROM NonProfit n
                            LEFT JOIN UserProfile up on n.OwnerId = up.Id
                                         WHERE n.Id = @Id;";

                    DbUtils.AddParameter(cmd, "@Id", id);

                    var reader = cmd.ExecuteReader();

                    NonProfit nonProfit = null;
                    if (reader.Read())
                    {
                        nonProfit = new NonProfit()
                        {
                            Id               = DbUtils.GetInt(reader, "Id"),
                            OwnerId          = DbUtils.GetInt(reader, "OwnerId"),
                            Name             = DbUtils.GetString(reader, "Name"),
                            Location         = DbUtils.GetString(reader, "Location"),
                            Cause            = DbUtils.GetString(reader, "Cause"),
                            Description      = DbUtils.GetString(reader, "Description"),
                            MissionStatement = DbUtils.GetString(reader, "MissionStatement"),
                            Website          = DbUtils.GetString(reader, "website"),
                            UserProfile      = new UserProfile()
                            {
                                Id          = DbUtils.GetInt(reader, "OwnerId"),
                                FirstName   = DbUtils.GetString(reader, "FirstName"),
                                LastName    = DbUtils.GetString(reader, "LastName"),
                                DisplayName = DbUtils.GetString(reader, "DisplayName"),
                                Email       = DbUtils.GetString(reader, "Email")
                            }
                        };
                    }

                    reader.Close();

                    return(nonProfit);
                }
            }
        }
        public IHttpActionResult PutNonProfit(string id, NonProfit nonProfit)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != nonProfit.Id)
            {
                return(BadRequest());
            }

            // overwrites Password and SecurityStamp
            //db.Entry(nonProfit).State = EntityState.Modified;

            // ensures Password and SecurityStamp are retained
            var originalNonProfit = db.NonProfits.Find(id);

            try
            {
                originalNonProfit.UserName     = nonProfit.UserName;
                originalNonProfit.FirstName    = nonProfit.FirstName;
                originalNonProfit.LastName     = nonProfit.LastName;
                originalNonProfit.Email        = nonProfit.Email;
                originalNonProfit.Name         = nonProfit.Name;
                originalNonProfit.WebsiteURL   = nonProfit.WebsiteURL;
                originalNonProfit.CalendarLink = nonProfit.CalendarLink;
                originalNonProfit.Description  = nonProfit.Description;
                originalNonProfit.Active       = nonProfit.Active;
                // Id, Password, and SecurityStamp are not updated

                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!NonProfitExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult GetEventById(string nonprofitId, int eventId)
        {
            var db = new ApplicationDbContext();

            NonProfit nonProfit = db.NonProfits.Find(nonprofitId);
            Event     thisEvent = db.Events.Find(eventId);

            if (nonProfit == null)
            {
                return(NotFound());
            }

            var eventList = new
            {
                nonProfitName = nonProfit.Name,
                Events        = nonProfit.Events
            };

            return(Ok(thisEvent));
            //return Ok(nonProfit.Events);
        }
Exemplo n.º 15
0
        public ActionResult Delete(int id)
        {
            NonProfit thisNonProfit = _db.NonProfits.FirstOrDefault(nonProfits => nonProfits.NonProfitId == id);

            return(View(thisNonProfit));
        }
Exemplo n.º 16
0
 public ActionResult Edit(NonProfit NonProfit)
 {
     _db.Entry(NonProfit).State = EntityState.Modified;
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
Exemplo n.º 17
0
        protected override void Seed(NashConnects.Models.ApplicationDbContext context)
        {
            //SEED WITH ADMIN USER
            var adminRole = new IdentityRole("Admin");

            context.Roles.AddOrUpdate(r => r.Name, adminRole);
            context.SaveChanges();

            var userManager = new ApplicationUserManager(new UserStore <ApplicationUser>(context));

            var user = new ApplicationUser
            {
                UserName   = "******",
                Email      = "*****@*****.**",
                FirstName  = "Sharon",
                LastName   = "Smith",
                WebsiteURL = "xxx.com",
            };

            userManager.CreateAsync(user, "password").Wait();
            var addedUser = context.Users.First(x => x.UserName == user.UserName);

            userManager.AddToRoleAsync(addedUser.Id, "Admin").Wait();


            //SEED WITH FREELANCE USERS
            var user2 = new Freelancer
            {
                UserName   = "******",
                Email      = "*****@*****.**",
                FirstName  = "Carol",
                LastName   = "Frazier",
                WebsiteURL = "http://www.bestuwellness.com/"
            };

            userManager.CreateAsync(user2, "password").Wait();

            var user3 = new Freelancer
            {
                UserName   = "******",
                Email      = "*****@*****.**",
                FirstName  = "Thomas",
                LastName   = "Petillo",
                WebsiteURL = "http://www.thomaspetillo.com/"
            };

            userManager.CreateAsync(user3, "password").Wait();

            var user4 = new Freelancer
            {
                UserName   = "******",
                Email      = "*****@*****.**",
                FirstName  = "Patrick",
                LastName   = "Carr",
                WebsiteURL = "http://www.patrickwcarr.com/"
            };

            userManager.CreateAsync(user4, "password").Wait();

            var user5 = new Freelancer
            {
                UserName   = "******",
                Email      = "*****@*****.**",
                FirstName  = "Ian",
                LastName   = "Cron",
                WebsiteURL = "http://iancron.com/"
            };

            userManager.CreateAsync(user5, "password").Wait();

            var user6 = new Freelancer
            {
                UserName   = "******",
                Email      = "*****@*****.**",
                FirstName  = "Nita",
                LastName   = "Andrews",
                WebsiteURL = "http://creativelectio.com/"
            };

            userManager.CreateAsync(user6, "password").Wait();

            var user8 = new Freelancer
            {
                UserName   = "******",
                Email      = "*****@*****.**",
                FirstName  = "Barbara",
                LastName   = "Sanders",
                WebsiteURL = "http://www.barbarasanderslcsw.com/"
            };

            userManager.CreateAsync(user8, "password").Wait();

            var user9 = new Freelancer
            {
                UserName   = "******",
                Email      = "*****@*****.**",
                FirstName  = "Patrick",
                LastName   = "Nitch",
                WebsiteURL = "http://www.mindfultherapynashville.com/neighborhood/"
            };

            userManager.CreateAsync(user9, "password").Wait();

            var user10 = new Freelancer
            {
                UserName   = "******",
                Email      = "*****@*****.**",
                FirstName  = "Rod",
                LastName   = "Kochtitzky",
                WebsiteURL = "https://rodk.net/"
            };

            userManager.CreateAsync(user10, "password").Wait();

            var user11 = new Freelancer
            {
                UserName   = "******",
                Email      = "*****@*****.**",
                FirstName  = "Mitchell",
                LastName   = "Blom",
                WebsiteURL = "http://mitchellblom.com/#!/about"
            };

            userManager.CreateAsync(user11, "password").Wait();

            var user12 = new Freelancer
            {
                UserName   = "******",
                Email      = "*****@*****.**",
                FirstName  = "Ben",
                LastName   = "Greaves",
                WebsiteURL = "https://bsgreaves.github.io/portfolio/"
            };

            userManager.CreateAsync(user12, "password").Wait();

            var user17 = new Freelancer
            {
                UserName   = "******",
                Email      = "*****@*****.**",
                FirstName  = "Tim",
                LastName   = "Villager",
                WebsiteURL = "https://fridrichandclark.com/agents/tim-villager/"
            };

            userManager.CreateAsync(user17, "password").Wait();

            var user18 = new Freelancer
            {
                UserName   = "******",
                Email      = "*****@*****.**",
                FirstName  = "Troy",
                LastName   = "Villager",
                WebsiteURL = "https://www.tvillagerdesigns.com/"
            };

            userManager.CreateAsync(user18, "password").Wait();


            //SEED WITH NON-PROFIT USERS
            var user7 = new NonProfit
            {
                UserName   = "******",
                Email      = "*****@*****.**",
                FirstName  = "Al",
                LastName   = "Andrews",
                WebsiteURL = "http://porterscall.com/"
            };

            userManager.CreateAsync(user7, "password").Wait();

            var user13 = new NonProfit
            {
                UserName   = "******",
                Email      = "*****@*****.**",
                FirstName  = "Liz",
                LastName   = "Williams",
                WebsiteURL = "http://makenashville.org/"
            };

            userManager.CreateAsync(user13, "password").Wait();

            var user14 = new NonProfit
            {
                UserName   = "******",
                Email      = "*****@*****.**",
                FirstName  = "Sarah",
                LastName   = "Carroll",
                WebsiteURL = "https://www.ec.co/"
            };

            userManager.CreateAsync(user14, "password").Wait();

            var user15 = new NonProfit
            {
                UserName   = "******",
                Email      = "*****@*****.**",
                FirstName  = "Sue",
                LastName   = "Farley",
                WebsiteURL = "https://creativemornings.com/"
            };

            userManager.CreateAsync(user15, "password").Wait();

            var user16 = new NonProfit
            {
                UserName   = "******",
                Email      = "*****@*****.**",
                FirstName  = "Essie",
                LastName   = "Sappenfield",
                WebsiteURL = "http://www.theskillery.com/"
            };

            userManager.CreateAsync(user16, "password").Wait();



            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //
        }
Exemplo n.º 18
0
 public ActionResult Create(NonProfit nonProfit)
 {
     _db.NonProfits.Add(nonProfit);
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }