Пример #1
0
        public IHttpActionResult PutWorker([FromUri] int id, [FromBody] Worker worker)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #2
0
        public IHttpActionResult PutContact(int id, Contact contact)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
 public ActionResult Edit([Bind(Include = "Id,batch1,year")] batch batch)
 {
     if (ModelState.IsValid)
     {
         db.Entry(batch).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(batch));
 }
Пример #4
0
 public ActionResult Edit([Bind(Include = "Id,firstname,lastname,username,password")] user user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(user));
 }
 public ActionResult Edit([Bind(Include = "Id,course1,duration")] course course)
 {
     if (ModelState.IsValid)
     {
         db.Entry(course).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(course));
 }
 public ActionResult Edit([Bind(Include = "Id,firstname,lastname,nic,course_id,batch_id,telno")] registration registration)
 {
     if (ModelState.IsValid)
     {
         db.Entry(registration).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.batch_id = new SelectList(db.batches, "Id", "batch1", registration.batch_id);
     ViewBag.course_id = new SelectList(db.courses, "Id", "course1", registration.course_id);
     return View(registration);
 }
Пример #7
0
        public void deleteUser(int id)
        {
            User u = db.userTable.Find(id);

            if (u.UserRole == (userRole)1)             // customer
            {
                foreach (Project p in u.ownProject.ToList())
                {
                    db.ProjectTable.Remove(p);
                }
                List <Reports> data = (from x in db.ReportsTable
                                       where x.customer.ID == id
                                       select x).ToList();
                foreach (Reports r in data)
                {
                    db.ReportsTable.Remove(r);
                }
            }
            else if (u.UserRole == (userRole)2)              //projectManager
            {
                List <Project> projects = (from x in db.ProjectTable
                                           where x.projectManager.ID == id
                                           select x).ToList();
                foreach (Project p in projects)
                {
                    Project proj = db.ProjectTable.Find(p.ID);
                    proj.status    = (status)0;
                    proj.startDate = null;
                    proj.endDate   = null;
                    db.Entry(proj).Reference("projectManager").CurrentValue = null;
                    db.Entry(proj).Reference("teamLeader").CurrentValue     = null;
                    proj.price = null;
                    proj.workers.Clear();
                }
                List <Feedback> feedbacks = (from x in db.FeedbackTable
                                             where x.projectManager.ID == id
                                             select x).ToList();
                foreach (Feedback f in feedbacks)
                {
                    db.FeedbackTable.Remove(f);
                }
                List <Qualifications> qualifications = (from x in db.qualificationsTable
                                                        where x.user.ID == id
                                                        select x).ToList();
                foreach (Qualifications q in qualifications)
                {
                    db.qualificationsTable.Remove(q);
                }
                List <Reports> reports = (from x in db.ReportsTable
                                          where x.projectManager.ID == id
                                          select x).ToList();
                foreach (Reports r in reports)
                {
                    db.ReportsTable.Remove(r);
                }
            }
            else if (u.UserRole == (userRole)3)              //teamLeader
            {
                foreach (Project p in u.leadProject.ToList())
                {
                    Project proj = db.ProjectTable.Find(p.ID);
                    db.Entry(proj).Reference("teamLeader").CurrentValue = null;
                }
                List <Feedback> feedbacks = (from x in db.FeedbackTable
                                             where x.teamLeader.ID == id
                                             select x).ToList();
                foreach (Feedback f in feedbacks)
                {
                    db.FeedbackTable.Remove(f);
                }
                List <Qualifications> qulaifications = (from x in db.qualificationsTable
                                                        where x.user.ID == id
                                                        select x).ToList();
                foreach (Qualifications q in qulaifications)
                {
                    db.qualificationsTable.Remove(q);
                }
            }
            else if (u.UserRole == (userRole)4)              //juniorEngineer
            {
                List <Feedback> feedbacks = (from x in db.FeedbackTable
                                             where x.juniorEngineering.ID == id
                                             select x).ToList();
                foreach (Feedback f in feedbacks)
                {
                    db.FeedbackTable.Remove(f);
                }
                var qulaifications = (from x in db.qualificationsTable
                                      where x.user.ID == id
                                      select x).ToList();
                foreach (Qualifications q in qulaifications)
                {
                    db.qualificationsTable.Remove(q);
                }
            }
            db.userTable.Remove(u);
            db.SaveChanges();
        }