Пример #1
0
        public async Task <Object> Add(CourseViewModel course)
        {
            if (ModelState.IsValid)
            {
                Course newrecord = new Course
                {
                    ID      = course.ID,
                    Name    = course.Name,
                    Classes = authDb.Classes.Where(a => a.ID == course.Class).FirstOrDefault()
                };

                if (newrecord.ID != 0)
                {
                    authDb.Entry(newrecord).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                }
                else
                {
                    var checkrecored = await Task.Run(() => authDb.Courses.Where(a => a.Name == newrecord.Name && a.Classes == newrecord.Classes).FirstOrDefault());

                    if (checkrecored != null)
                    {
                        return(BadRequest("recored of subject " + course.Name + " in class " + course.Class + " is already added"));
                    }
                    await Task.Run(() => authDb.AddAsync(newrecord));
                }
                await authDb.SaveChangesAsync();

                return(Ok("recored saved successfully"));
            }
            return(BadRequest(ModelState));
        }
        public async Task <Object> AddClass(Classes model)

        {
            if (ModelState.IsValid)
            {
                var newclass = new Classes()
                {
                    ID      = model.ID,
                    Name    = model.Name,
                    Fee     = model.Fee,
                    Section = model.Section
                };

                if (model.ID != 0)
                {
                    db.Entry(newclass).State = EntityState.Modified;
                }
                else
                {
                    Classes record = await Task.Run(() => db.Classes.Where(a => a.Name == model.Name && a.Section == model.Section).FirstOrDefault());

                    if (record != null)
                    {
                        return(BadRequest("class is added already!"));
                    }
                    await Task.Run(() => db.Classes.AddAsync(newclass));
                }
                await db.SaveChangesAsync();

                return(Ok());
            }
            return(BadRequest());
        }
Пример #3
0
        public async Task <Object> Add(PeriodRecored recored)
        {
            if (ModelState.IsValid)
            {
                PeriodDetail model = new PeriodDetail
                {
                    ID      = recored.ID,
                    Course  = authDb.Courses.Where(a => a.ID == recored.Course).FirstOrDefault(),
                    Teacher = authDb.Teachers.Where(a => a.ID == recored.Teacher).FirstOrDefault(),
                    Classes = authDb.Classes.Where(a => a.Name == recored.Classes && a.Section == recored.Section).FirstOrDefault(),
                    Period  = recored.Period,
                };
                if (model.ID != 0)
                {
                    await Task.Run(() => authDb.Entry(model).State = EntityState.Modified);
                }
                else
                {
                    await Task.Run(() => authDb.AddAsync(model));
                }
                await authDb.SaveChangesAsync();

                return(Ok());
            }
            return(BadRequest("data is not valid"));
        }
        public async Task <object> Add(StudentModel model)
        {
            for (int i = 1; i < 201; i++)
            {
                try
                {
                    model.ClassId = new Random().Next(1, 11);
                    Students NewStudent = new Students();
                    NewStudent.ID          = model.ID;
                    NewStudent.Name        = model.Name + i;
                    NewStudent.Father      = model.Father + i;
                    NewStudent.Class       = authDb.Classes.Where(a => a.ID == model.ClassId).FirstOrDefault();
                    NewStudent.DateOfBirth = model.DateOfBirth;
                    if (NewStudent.ID != 0)
                    {
                        authDb.Entry(NewStudent).State = EntityState.Modified;
                    }
                    else
                    {
                        await Task.Run(() => authDb.AddAsync(NewStudent));
                    }

                    await authDb.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                }
            }
            return(Ok());
        }
Пример #5
0
        public async Task <Object> Add(MarksList model)
        {
            if (ModelState.IsValid)
            {
                MarkslistData markslistData = new MarkslistData
                {
                    ID       = model.ID,
                    Classes  = authDb.Classes.Where(a => a.ID == model.Class).FirstOrDefault(),
                    Course   = authDb.Courses.Where(a => a.ID == model.Subject).FirstOrDefault(),
                    Students = authDb.Students.Where(a => a.ID == model.Student).FirstOrDefault(),
                    Marks    = model.Marks,
                    Total    = model.Total
                };
                if (markslistData.ID != 0)
                {
                    authDb.Entry(markslistData).State = EntityState.Modified;
                }
                else
                {
                    await authDb.AddAsync(markslistData);
                }
                await authDb.SaveChangesAsync();

                return(Ok("Added successfully"));
            }
            return(BadRequest("Error"));
        }
        public async Task <Object> Add(Teacher teacher)
        {
            try
            {
                if (DateTime.Compare(Convert.ToDateTime(teacher.CompletionDate.ToString()), DateTime.UtcNow.Date) > 0 || DateTime.Compare(Convert.ToDateTime(teacher.CompletionDate.ToString()), DateTime.UtcNow.Date) == 0)
                {
                    ModelState.AddModelError("CompletionDate", "Date is invalid");
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError("CompletionDate", e.ToString());
            }

            if (ModelState.IsValid)
            {
                Teacher newrecored = new Teacher
                {
                    ID             = teacher.ID,
                    Name           = teacher.Name,
                    Cnic           = teacher.Cnic,
                    Education      = teacher.Education,
                    Institute      = teacher.Institute,
                    CompletionDate = teacher.CompletionDate,
                };

                if (newrecored.ID != 0)
                {
                    authDb.Entry(newrecored).State = EntityState.Modified;
                }
                else
                {
                    var checkrecored = await Task.Run(() => authDb.Teachers.Where(a => a.Cnic == newrecored.Cnic).FirstOrDefault());

                    if (checkrecored != null)
                    {
                        return(BadRequest("recored with this cnic number is added already"));
                    }
                    await Task.Run(() => authDb.AddAsync(newrecored));
                }
                await authDb.SaveChangesAsync();

                return(Ok("recored updated already"));
            }
            return(BadRequest(ModelState));
        }