예제 #1
0
        public async Task <IHttpActionResult> PutEmployee(int id, Employee employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != employee.ID)
            {
                return(BadRequest());
            }

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

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EmployeeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        // PUT api/<TrainingCategory>/5
        public IHttpActionResult PutTrainingCategory(TrainingCategory trainingCategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #3
0
 public ActionResult Edit(Trainer trainer)
 {
     if (ModelState.IsValid)
     {
         context.Entry(trainer).State = EntityState.Modified;
         context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(trainer));
 }
예제 #4
0
 public ActionResult Edit(Training training)
 {
     if (ModelState.IsValid)
     {
         context.Entry(training).State = EntityState.Modified;
         context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.PossibleTrainers = context.Trainers;
     return(View(training));
 }
예제 #5
0
        // PUT api/<Trainer>/ id
        public IHttpActionResult PutTrainer(Trainer objOfTrainer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #6
0
 public async Task SaveListings(TMSContext context)
 {
     foreach (var listing in Listings)
     {
         var oldListing = context.Listings.FirstOrDefault(x => x.CRN == listing.CRN && x.Term.TermID == listing.Term.TermID);
         if (oldListing != null && !oldListing.IsEqual(listing))
         {
             oldListing.Subject           = listing.Subject;
             oldListing.CourseNumber      = listing.CourseNumber;
             oldListing.InstructionType   = listing.InstructionType;
             oldListing.InstructionMethod = listing.InstructionMethod;
             oldListing.Section           = listing.Section;
             oldListing.MaxEnroll         = listing.MaxEnroll;
             oldListing.Enroll            = listing.Enroll;
             oldListing.CourseTitle       = listing.CourseTitle;
             oldListing.Times             = listing.Times;
             oldListing.Instructor        = listing.Instructor;
             oldListing.ModifiedDate      = DateTime.Now;
             Updated += 1;
         }
         else
         {
             New += 1;
             context.Add(listing);
         }
     }
     foreach (var term in Terms)
     {
         if (context.Terms.Any(x => x.LookupLabel == term.LookupLabel))
         {
             var oldTerm = context.Terms.First(x => x.LookupLabel == term.LookupLabel);
             context.Entry(oldTerm).CurrentValues.SetValues(term);
         }
         else
         {
             context.Add(term);
         }
     }
     context.SaveChanges();
 }
 public bool Update(TEntity entity)
 {
     _context.Entry(entity).State = EntityState.Modified;
     return(_context.SaveChanges() > 0);
 }