Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        public NGOModel Post([FromBody] NGOModel ngo)
        {
            Response.StatusCode = 201;
            string result = NGOService.CreateNGO(ngo, dbConn);

            ngo.Id = Convert.ToInt32(result);
            return(ngo);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
 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");
     }
 }
Ejemplo n.º 6
0
        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());
        }
Ejemplo n.º 7
0
 public string UpdateNGO([FromRoute] int id, [FromBody] NGOModel ngo)
 {
     return(NGOService.UpdateNGO(ngo, dbConn));
 }