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());
        }
        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());
        }
Exemplo n.º 3
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"));
        }
Exemplo n.º 4
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(InitData model)
        {
            if (ModelState.IsValid)
            {
                var check = authDb.DateSheetInitial.Where(a => a.Start == model.Start && a.End == model.End).FirstOrDefault();
                if (check != null)
                {
                    return(BadRequest("datesheet is already created "));
                }
                await authDb.DateSheetInitial.AddAsync(model);

                await authDb.SaveChangesAsync();

                return(Ok(authDb.DateSheetInitial.Where(a => a.Start == model.Start && a.End == model.End).Select(a => a.ID)));
            }
            return(BadRequest(ModelState));
        }
        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));
        }
Exemplo n.º 7
0
        public async Task <Object> Delete(int id = 0)
        {
            if (id != 0)
            {
                Course course = await Task.Run(() => authDb.Courses.Where(a => a.ID == id).FirstOrDefault());

                if (course != null)
                {
                    await Task.Run(() => authDb.Remove(course));

                    await authDb.SaveChangesAsync();

                    return(Ok("deleted successfully"));
                }
                else
                {
                    return(BadRequest("data not found"));
                }
            }
            return(BadRequest("invalid id"));
        }