public static string CreateNGO(NGOModel ngo, string connstring) { Dictionary <string, object> spParams = new Dictionary <string, object>(); spParams.Add("@Name", ngo.Name); return(DBAccess.ExecuteSQLScalar(connstring, "CALL usp_InsertNGO(@Name)", spParams)); }
public async Task <ActionResult <NGOModel> > GetByID(Guid id) { NGO ngo = await applicationDbContext.NGOs.FindAsync(id); if (ngo == null) { return(NotFound()); } NGOModel ngoModel = new NGOModel { Id = ngo.ID, Name = ngo.Name, Status = ngo.NGOStatus, CreatedBy = applicationDbContext.Users.Find(ngo.CreatedByID.ToString()).Email, HeadquartersAddress = ngo.HeadquartersAddress, HeadquartersPhoneNumber = ngo.HeadquartersPhoneNumber, HeadquartersEmail = ngo.HeadquartersEmail, IdentificationNumber = ngo.IdentificationNumber, Website = ngo.Website, CategoryName = applicationDbContext.Categories.FirstOrDefault(c => c.ID == ngo.CategoryID)?.Name, ServiceName = applicationDbContext.Services.FirstOrDefault(c => c.ID == ngo.ServiceID)?.Name }; return(ngoModel); }
public NGOModel Post([FromBody] NGOModel ngo) { Response.StatusCode = 201; string result = NGOService.CreateNGO(ngo, dbConn); ngo.Id = Convert.ToInt32(result); return(ngo); }
public async Task <ActionResult <NGOModel> > VerifyByID(NGOModel ngoModel) { NGO ngo = await applicationDbContext.NGOs.FindAsync(ngoModel.Id); if (ngo != null) { ngo.NGOStatus = NGOStatus.Verified; ngoModel.Status = ngo.NGOStatus; await applicationDbContext.SaveChangesAsync(); } return(ngoModel); }
public static string UpdateNGO(NGOModel ngo, string connstring) { try { Dictionary <string, object> spParams = new Dictionary <string, object>(); spParams.Add("@Id", ngo.Id); spParams.Add("@Name", ngo.Name); return(DBAccess.ExecuteSQLNonQuery(connstring, "CALL usp_UpdateNGO(@Id, @Name)", spParams)); } catch (Exception) { return("An error occurred"); } }
public async Task <ActionResult <IEnumerable <NGOModel> > > GetNGOs() { List <NGOModel> ngoModels = new List <NGOModel>(); List <NGO> ngos = await applicationDbContext.NGOs.ToListAsync(); if (ngos.Any()) { foreach (NGO ngo in ngos) { NGOModel ngoModel = new NGOModel { Id = ngo.ID, Name = ngo.Name, Status = ngo.NGOStatus, CreatedBy = applicationDbContext.Users.Find(ngo.CreatedByID.ToString()).Email }; ngoModels.Add(ngoModel); } } return(ngoModels.OrderBy(n => n.Name).ToList()); }
public string UpdateNGO([FromRoute] int id, [FromBody] NGOModel ngo) { return(NGOService.UpdateNGO(ngo, dbConn)); }