Exemple #1
0
        public RequirementsViewModel GetRequirements(int id)

        {
            RequirementsViewModel RequirementsViewModel = new RequirementsViewModel();

            NGOdata.Requirements GetRequirements;

            GetRequirements = db.Requirements.Where(x => x.Id == id).FirstOrDefault();

            Mapper.CreateMap <Requirements, RequirementsViewModel>();
            RequirementsViewModel = Mapper.Map <Requirements, RequirementsViewModel>(GetRequirements);

            return(RequirementsViewModel);
        }
Exemple #2
0
        public IHttpActionResult PostRequirementsViewModel(RequirementsViewModel requirementsViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Requirements Requirements = new Requirements();

            Mapper.CreateMap <RequirementsViewModel, Requirements>();
            Requirements = Mapper.Map <RequirementsViewModel, Requirements>(requirementsViewModel);

            db.Requirements.Add(Requirements); db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = requirementsViewModel.Id }, requirementsViewModel));
        }
Exemple #3
0
        // GET: api/Requirements
        public List <RequirementsViewModel> GetRequirements()
        {
            var RequirementsList = db.Requirements.ToList();

            List <RequirementsViewModel> RequirementsViewModelList = new List <RequirementsViewModel>();

            foreach (var item in RequirementsList)
            {
                RequirementsViewModel RequirementsViewModel = new RequirementsViewModel();

                Mapper.CreateMap <Requirements, RequirementsViewModel>();
                RequirementsViewModel = Mapper.Map <Requirements, RequirementsViewModel>(item);

                RequirementsViewModelList.Add(RequirementsViewModel);
            }


            return(RequirementsViewModelList);
        }
Exemple #4
0
        public IHttpActionResult PutRequirementsViewModel(int id, RequirementsViewModel requirementsViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            Requirements Requirements = new Requirements();

            Mapper.CreateMap <RequirementsViewModel, Requirements>();
            Requirements = Mapper.Map <RequirementsViewModel, Requirements>(requirementsViewModel);
            db.Entry(Requirements).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }