public async Task <string> EditApi([FromBody] Classs item)
        {
            try
            {
                var dbItem = _context.Classs.FirstOrDefault(m => m.ClasssId == item.ClasssId);

                dbItem.ClasseName    = item.ClasseName;
                dbItem.Level         = item.Level;
                dbItem.NbreEtudiants = item.NbreEtudiants;
                dbItem.Speciality    = item.Speciality;
                _context.Update(dbItem);
                await _context.SaveChangesAsync();

                return(await Task.Factory.StartNew(() =>
                {
                    return JsonConvert.SerializeObject(dbItem);
                }));
            }
            catch (Exception ex)
            {
                var errorMessage = "Failure to PUT. Stack Trace: " + ex.StackTrace;
                Console.WriteLine(errorMessage);
                return(await Task.Factory.StartNew(() =>
                {
                    return JsonConvert.SerializeObject(new { msg = errorMessage });
                }));
            }
        }
        public async Task <dynamic> DeleteApi([FromBody] Classs cl)
        {
            try
            {
                var dbItem = _context.Classs.FirstOrDefault(m => m.ClasssId == cl.ClasssId);
                if (dbItem == null)
                {
                    return(await Task.Factory.StartNew(() =>
                    {
                        return JsonConvert.SerializeObject(new { msg = "Failure to DELETE.  Item not found." });
                    }));
                }
                _context.Classs.Remove(dbItem);
                await _context.SaveChangesAsync();

                return(await Task.Factory.StartNew(() =>
                {
                    return JsonConvert.SerializeObject(dbItem);
                }));
            }
            catch (Exception ex)
            {
                var errorMessage = "Failure to DELETE. Stack Trace: " + ex.StackTrace;
                Console.WriteLine(errorMessage);
                return(await Task.Factory.StartNew(() =>
                {
                    return JsonConvert.SerializeObject(new { msg = errorMessage });
                }));
            }
        }
        public async Task <IActionResult> Edit(int id, [Bind("id,NameOfClass")] Classs classs)
        {
            if (id != classs.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(classs);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ClasssExists(classs.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(classs));
        }
Esempio n. 4
0
        public ServiceResponse <Classs> Add(Classs classs)
        {
            var response = new ServiceResponse <Classs>();

            if (response.Validation(new ClasssValidation().Validate(classs)))
            {
                response.Result = classsRepository.Insert(classs);
            }

            return(response);
        }
        public async Task <IActionResult> Create([Bind("id,NameOfClass")] Classs classs)
        {
            if (ModelState.IsValid)
            {
                _context.Add(classs);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(classs));
        }
Esempio n. 6
0
        //we receive object from the form, we search list (using a pointer)
        //if we found it, we change attributes we want to change and send control elsewhere
        public ActionResult EditClasses(Classs myModel)
        {
            var obj = ClasssList.FirstOrDefault(x =>
                                                x.Class_Code == myModel.Class_Code);

            if (obj != null)
            {
                obj.Class_Title       = myModel.Class_Title;
                obj.Class_Description = myModel.Class_Description;
            }
            return(View("ShowClasses", ClasssList));
        }
Esempio n. 7
0
 public ActionResult AddClasses(Classs myClass)
 {
     if (ModelState.IsValid)
     {
         myClass.Class_Code = ClasssList.Count() + 1;
         ClasssList.Add(myClass);
         return(RedirectToAction("ShowClasses"));
     }
     else
     {
         return(View(myClass));
     }
 }
        public async Task <dynamic> Create([FromBody] Classs cll)
        {
            try
            {
                _context.Classs.Add(cll);
                await _context.SaveChangesAsync();

                return(await Task.Factory.StartNew(() => { return JsonConvert.SerializeObject(cll); }));
            }
            catch (Exception ex)
            {
                var errorMessage = "Failure to POST. Stack Trace: " + ex.StackTrace;
                Console.WriteLine(errorMessage);
                return(await Task.Factory.StartNew(() => { return JsonConvert.SerializeObject(new { msg = errorMessage }); }));
            }
        }
        public async Task <IActionResult> Edit(int id, [Bind("ClasssId,NbreEtudiants,Speciality,ClasseName,Level")] Classs clas)
        {
            if (id != clas.ClasssId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                _context.Update(clas);
                await _context.SaveChangesAsync();


                return(RedirectToAction("Index"));
            }
            return(View(clas));
        }
Esempio n. 10
0
        public ServiceResponse <Classs> Update(Classs classs)
        {
            var response = new ServiceResponse <Classs>();

            if (response.Validation(new ClasssValidation().Validate(classs)))
            {
                classsRepository.Detach(classs);

                var repositoryResponse = classsRepository.GetById(classs.Id);
                if (repositoryResponse != null)
                {
                    repositoryResponse.ClassName = classs.ClassName;
                    repositoryResponse.IsActive  = classs.IsActive;
                    response.Result = classsRepository.Update(repositoryResponse);
                }
                else
                {
                    response.SetError("Veri Bulunamadı");
                }
            }
            return(response);
        }
Esempio n. 11
0
        public static void CreateSchoolData()
        {
            // create classes
            Classs fiveB = new Classs("5B");
            Classs nineA = new Classs("9A");

            nineA.AddComments("some comments go here");

            // create students
            Student s1 = new Student("Student 1", fiveB);
            Student s2 = new Student("Student 2", fiveB);
            Student s3 = new Student("Student 3", nineA);
            Student s4 = new Student("Student 4", nineA);
            Student s5 = new Student("Student 5", nineA);

            // create discipline
            Discipline english   = new Discipline("English", 5, 20);
            Discipline math      = new Discipline("Math", 6, 25);
            Discipline chemistry = new Discipline("Chemistry", 2, 10);

            // create teachers and assign disciplines, resp. classes
            Teacher teach1 = new Teacher("Teach1");

            teach1.AddDiscipline(english);
            Teacher teach2 = new Teacher("Teach2");

            teach2.AddDiscipline(math);
            teach2.AddDiscipline(chemistry);
            Teacher teach3 = new Teacher("Teach3");

            teach3.AddDiscipline(english);
            teach3.AddDiscipline(math);

            fiveB.AddTeacher(teach1);
            fiveB.AddTeacher(teach2);
            nineA.AddTeacher(teach3);
        }
Esempio n. 12
0
 public async Task <bool> Update(Classs entity)
 {
     _db.Classes.Update(entity);
     return(await Save());
 }
Esempio n. 13
0
 public async Task <bool> Delete(Classs entity)
 {
     _db.Classes.Remove(entity);
     return(await Save());
 }
Esempio n. 14
0
        public async Task <bool> Create(Classs entity)
        {
            await _db.Classes.AddAsync(entity);

            return(await Save());
        }
Esempio n. 15
0
        public ActionResult EditClasses(int tCode)
        {
            Classs oClass = ClasssList.Find(x => x.Class_Code == tCode);

            return(View(oClass));
        }