Exemple #1
0
 public object AssignSubject(AssignSubject assignSubject)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.AssignSubject.Add(assignSubject);
             db.SaveChanges();
             return(new ResponseClass
             {
                 Status = 200,
                 Message = "Assign Subject SuccessFully",
                 Response = null
             });
         }
         else
         {
             return(new ResponseClass {
                 Status = 400, Message = "Data Not Valid", Response = null
             });
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemple #2
0
 public object UpdateAssignSubject(AssignSubject assignSubject)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.Entry(assignSubject).Property("Subjectidref").IsModified = true;
             db.SaveChanges();
             return(new ResponseClass
             {
                 Status = 200,
                 Message = "Assign Subject Updated cessFully",
                 Response = null
             });
         }
         else
         {
             return(new ResponseClass {
                 Status = 400, Message = "Data Not Valid", Response = null
             });
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemple #3
0
        public IHttpActionResult Post(AssignSubject assignSubject)
        {
            var item = assignSubjectRepo.Post(assignSubject);

            if (item != null)
            {
                return(Ok(item));
            }
            return(NotFound());
        }
Exemple #4
0
        public async Task <ActionResult> Create(AssignSubjectViewModel model)
        {
            if (ModelState.IsValid)
            {
                int    counter  = 0;
                string theClass = String.Empty;
                if (model.SubjectId != null)
                {
                    foreach (var term in model.TermName)
                    {
                        foreach (var item in model.SubjectId)
                        {
                            var CA = Db.AssignSubjects.Where(x => x.ClassName.Equals(model.ClassName) &&
                                                             x.SubjectId.Equals(item) &&
                                                             x.SchoolId.Equals(userSchool));
                            var countFromDb = await CA.CountAsync();

                            if (countFromDb >= 1)
                            {
                                TempData["UserMessage"] =
                                    $"Admin have already assigned {item} subject to {model.ClassName} Class";
                                TempData["Title"] = "Error.";
                                ViewBag.SubjectId = new MultiSelectList(await _query.SubjectListAsync(userSchool), "SubjectId", "SubjectName");
                                ViewBag.ClassName = new SelectList(await _query.ClassListAsync(userSchool),
                                                                   "FullClassName", "FullClassName");
                                ViewBag.TermName = new MultiSelectList(Db.Terms.AsNoTracking(), "TermName", "TermName");
                                return(View(model));
                            }
                            var assigSubject = new AssignSubject
                            {
                                ClassName = model.ClassName,
                                SubjectId = item,
                                TermName  = term,
                                SchoolId  = userSchool
                            };
                            Db.AssignSubjects.Add(assigSubject);
                            counter += 1;
                            theClass = model.ClassName;
                        }
                    }
                    await Db.SaveChangesAsync();

                    TempData["UserMessage"] = $" You have Assigned {counter} Subject(s)  to {theClass} Successfully.";
                    TempData["Title"]       = "Success.";
                    return(RedirectToAction("Index", "AssignSubjects"));
                }
            }

            ViewBag.SubjectId = new MultiSelectList(await _query.SubjectListAsync(userSchool), "SubjectId", "SubjectName");
            ViewBag.ClassName = new SelectList(await _query.ClassListAsync(userSchool), "FullClassName", "FullClassName");
            ViewBag.TermName  = new MultiSelectList(Db.Terms.AsNoTracking(), "TermName", "TermName");
            return(View(model));
        }
Exemple #5
0
        public async Task <ActionResult> Edit([Bind(Include = "AssignSubjectId,ClassName,SubjectName")] AssignSubject assignSubject)
        {
            if (ModelState.IsValid)
            {
                assignSubject.SchoolId        = userSchool;
                Db.Entry(assignSubject).State = EntityState.Modified;
                await Db.SaveChangesAsync();

                TempData["UserMessage"] = "Assigned Subject Updated Successfully.";
                TempData["Title"]       = "Success.";
                return(RedirectToAction("Index"));
            }
            ViewBag.SubjectId = new MultiSelectList(await _query.SubjectListAsync(userSchool), "SubjectId", "SubjectName");
            ViewBag.ClassName = new SelectList(await _query.ClassListAsync(userSchool), "FullClassName", "FullClassName");
            ViewBag.TermName  = new MultiSelectList(Db.Terms.AsNoTracking(), "TermName", "TermName");
            return(View(assignSubject));
        }
Exemple #6
0
        // GET: AssignSubjects/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AssignSubject assignSubject = await Db.AssignSubjects.FindAsync(id);

            if (assignSubject == null)
            {
                return(HttpNotFound());
            }
            ViewBag.SubjectId = new MultiSelectList(await _query.SubjectListAsync(userSchool), "SubjectId", "SubjectName");
            ViewBag.ClassName = new SelectList(await _query.ClassListAsync(userSchool), "FullClassName", "FullClassName");
            ViewBag.TermName  = new MultiSelectList(Db.Terms.AsNoTracking(), "TermName", "TermName");
            return(View(assignSubject));
        }
Exemple #7
0
 public object ActiveAssignSubject(AssignSubject assignSubject)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var request = db.AssignSubject.Where(c => c.Assignid.Equals(assignSubject.Assignid));
             if (request != null && assignSubject.IsActive != null)
             {
                 AssignSubject data = new AssignSubject
                 {
                     Assignid = assignSubject.Assignid,
                     IsActive = assignSubject.IsActive
                 };
                 db.Entry(data).Property("IsActive").IsModified = true;
                 db.SaveChanges();
                 return(new ResponseClass
                 {
                     Status = 200,
                     Message = "Assign Subject Updated SuccessFully",
                     Response = null
                 });
             }
             else
             {
                 return(new ResponseClass
                 {
                     Status = 403,
                     Message = "Server down please try after some time Name",
                     Response = null
                 });
             }
         }
         else
         {
             return(new ResponseClass {
                 Status = 400, Message = "Data Not Valid", Response = null
             });
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemple #8
0
        public AssignSubject Post(AssignSubject assignsubject)
        {
            var item = assignsubject.GetDataObject();

            using (var dbContext = new SMSEntities())
            {
                if (item.Id == 0)
                {
                    dbContext.assignsubjects.Add(item);
                    dbContext.SaveChanges();
                }
                else
                {
                    dbContext.Entry(item).State = EntityState.Modified;
                    dbContext.SaveChanges();
                }
            }
            assignsubject.Id = item.Id;
            return(assignsubject);
        }
Exemple #9
0
        public async Task <ActionResult> Save(AssignSubjectViewModel model)
        {
            bool   status  = false;
            string message = string.Empty;

            if (ModelState.IsValid)
            {
                int    counter  = 0;
                string theClass = String.Empty;
                if (model.AssignSubjectId > 0)
                {
                    var assignSubject = await Db.AssignSubjects.FindAsync(model.AssignSubjectId);

                    if (assignSubject != null)
                    {
                        assignSubject.SchoolId        = userSchool;
                        Db.Entry(assignSubject).State = EntityState.Modified;
                    }
                    message = "Class Updated Successfully...";
                }
                else
                {
                    foreach (var term in model.TermName)
                    {
                        foreach (var item in model.SubjectId)
                        {
                            var CA = Db.AssignSubjects.Where(x => x.ClassName.Equals(model.ClassName) &&
                                                             x.SubjectId.Equals(item) &&
                                                             x.SchoolId.Equals(userSchool));
                            var countFromDb = await CA.CountAsync();

                            if (countFromDb >= 1)
                            {
                                message = $"Admin have already assigned {item} subject to {model.ClassName} Class";
                                return(new JsonResult {
                                    Data = new { status = false, message = message }
                                });
                            }
                            var assigSubject = new AssignSubject
                            {
                                ClassName = model.ClassName,
                                SubjectId = item,
                                TermName  = term,
                                SchoolId  = userSchool
                            };
                            Db.AssignSubjects.Add(assigSubject);
                            counter += 1;
                            theClass = model.ClassName;
                        }
                    }
                    await Db.SaveChangesAsync();

                    message = $" You have Assigned {counter} Subject(s)  to {theClass} Successfully.";

                    return(new JsonResult {
                        Data = new { status = true, message = message }
                    });
                }
            }
            return(new JsonResult {
                Data = new { status = status, message = message }
            });
            //return View(subject);
        }