Beispiel #1
0
 public PlanModel GetPlanById(int planId)
 {
     //unitOfWork.StartTransaction();
     PlanRepository planRepository = new PlanRepository(unitOfWork);
     PlanModel planModel = new PlanModel();
     Plan plan = new Plan();
     plan = planRepository.GetAll().Where(x => x.PlanId == planId).FirstOrDefault();
     //unitOfWork.Commit();
     AutoMapper.Mapper.Map(plan, planModel);
     return planModel;
 }
Beispiel #2
0
        public IHttpActionResult PutPlan(int id, Plan plan)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != plan.PlanId)
            {
                return BadRequest();
            }

            db.Entry(plan).State = EntityState.Modified;

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

            return StatusCode(HttpStatusCode.NoContent);
        }
Beispiel #3
0
        public IHttpActionResult PostPlan(Plan plan)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Plans.Add(plan);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = plan.PlanId }, plan);
        }