public async Task <IHttpActionResult> DeleteCommunityImage(int id) { CommunityImage communityImage = await db.CommunityImages.FindAsync(id); if (communityImage == null) { return(NotFound()); } db.CommunityImages.Remove(communityImage); await db.SaveChangesAsync(); return(Ok(communityImage)); }
public async Task <Response <CommunityImage> > GetCommunityImagebyID(int id) { Response <CommunityImage> responceCommunityEmergencyContacts = new Response <CommunityImage>(); CommunityImage communityImage = await db.CommunityImages.FindAsync(id); if (communityImage == null) { responceCommunityEmergencyContacts.status = "Failed: No Community Image Found"; responceCommunityEmergencyContacts.model = null; return(responceCommunityEmergencyContacts); } responceCommunityEmergencyContacts.status = "Success"; responceCommunityEmergencyContacts.model = communityImage; return(responceCommunityEmergencyContacts); }
public async Task <Response <CommunityImage> > PostCommunityImage(CommunityImage communityImage) { Response <CommunityImage> responceCommunityEmergencyContacts = new Response <CommunityImage>(); if (!ModelState.IsValid) { responceCommunityEmergencyContacts.status = "Failure"; responceCommunityEmergencyContacts.model = null; return(responceCommunityEmergencyContacts); } db.CommunityImages.Add(communityImage); await db.SaveChangesAsync(); responceCommunityEmergencyContacts.status = "Success"; responceCommunityEmergencyContacts.model = communityImage; return(responceCommunityEmergencyContacts); }
public async Task <Response <CommunityImage> > PutCommunityImage(int id, CommunityImage communityImage) { Response <CommunityImage> responceCommunityEmergencyContacts = new Response <CommunityImage>(); if (!ModelState.IsValid) { responceCommunityEmergencyContacts.status = "Failure"; responceCommunityEmergencyContacts.model = null; return(responceCommunityEmergencyContacts); } if (id != communityImage.id) { responceCommunityEmergencyContacts.status = "Failed: CommunityID did not Match"; responceCommunityEmergencyContacts.model = null; return(responceCommunityEmergencyContacts); } db.Entry(communityImage).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CommunityImageExists(id)) { responceCommunityEmergencyContacts.status = "Failed: Id did not Exist"; responceCommunityEmergencyContacts.model = null; return(responceCommunityEmergencyContacts); } else { responceCommunityEmergencyContacts.status = "Failed: DB Exception"; responceCommunityEmergencyContacts.model = null; return(responceCommunityEmergencyContacts); } } responceCommunityEmergencyContacts.status = "Success"; responceCommunityEmergencyContacts.model = communityImage; return(responceCommunityEmergencyContacts); }
protected override void Seed(Neighbours.Data.NeighboursDbContext context) { if (!context.Users.Any()) { var maleImage = new ProfileImage() { FileExtension = "png", OriginalFileName = "male.png", NewFileName = "male.png", UrlPath = "~/Content/imgs", }; context.ProfileImages.Add(maleImage); var femaleImage = new ProfileImage() { FileExtension = "png", OriginalFileName = "female.png", NewFileName = "female.png", UrlPath = "~/Content/imgs", }; context.ProfileImages.Add(femaleImage); var otherImage = new ProfileImage() { FileExtension = "png", OriginalFileName = "other.png", NewFileName = "other.png", UrlPath = "~/Content/imgs", }; context.ProfileImages.Add(otherImage); var coverImage = new CommunityImage() { FileExtension = "jpg", OriginalFileName = "default-cover.png", NewFileName = "default-cover.png", UrlPath = "~/Content/imgs", }; context.SaveChanges(); var roleStore = new RoleStore <IdentityRole>(context); var roleManager = new RoleManager <IdentityRole>(roleStore); var userStore = new UserStore <User>(context); var userManager = new UserManager <User>(userStore); userManager.PasswordValidator = new PasswordValidator() { RequiredLength = 5, }; // Add missing roles var roleSuper = roleManager.FindByName("SuperUser"); if (roleSuper == null) { roleSuper = new IdentityRole("SuperUser"); roleManager.Create(roleSuper); } var roleAdmin = roleManager.FindByName("Administrator"); if (roleAdmin == null) { roleAdmin = new IdentityRole("Administrator"); roleManager.Create(roleAdmin); } var roleUser = roleManager.FindByName("User"); if (roleUser == null) { roleUser = new IdentityRole("User"); roleManager.Create(roleUser); } // Create test users var userSuper = userManager.FindByEmail("*****@*****.**"); if (userSuper == null) { var newSuper = new User() { Email = "*****@*****.**", FirstName = "Super", LastName = "Superov", UserName = "******", Gender = Gender.Other, BirthDate = new DateTime(1980, 1, 1), ProfileImageId = 1, }; userManager.Create(newSuper, "super"); userManager.AddToRole(newSuper.Id, "SuperUser"); } var userAdmin = userManager.FindByEmail("*****@*****.**"); if (userAdmin == null) { var newAdmin = new User() { Email = "*****@*****.**", FirstName = "Admin", LastName = "Adminov", UserName = "******", Gender = Gender.Other, BirthDate = new DateTime(1980, 1, 1), ProfileImageId = 2 }; userManager.Create(newAdmin, "admin"); userManager.AddToRole(newAdmin.Id, "Administrator"); } var user = userManager.FindByEmail("*****@*****.**"); if (user == null) { var newAdmin = new User() { Email = "*****@*****.**", FirstName = "User", LastName = "Userov", UserName = "******", Gender = Gender.Male, BirthDate = new DateTime(1980, 1, 1), ProfileImageId = 3 }; userManager.Create(newAdmin, "user1"); userManager.AddToRole(newAdmin.Id, "User"); } } }