Пример #1
0
        public bool SaveStudent(StudentDTO dto)
        {
            using (var ctx = new SMSContext())
            {
                if (dto.StudentID > 0)
                {
                    //Update
                    var query = from p in ctx.Students
                                where p.StudentID == dto.StudentID
                                select p;

                    //Now query will be executed on DB and will return result
                    var result = query.FirstOrDefault();

                    if (result != null)
                    {
                        result.StudentName = dto.StudentName;
                        result.FatherName = dto.FatherName;
                    }

                }
                else
                {
                    ctx.Students.Add(dto);
                }

                ctx.SaveChanges();
            }
            return true;
        }
        public JsonResult SaveStudent(StudentDTO dto)
        {
            StudentDAL dal = new StudentDAL();
            dal.SaveStudent(dto);

            var obj = new
            {
                success = true,
                message = "Record has been saved successfully"
            };

            return Json(obj, JsonRequestBehavior.AllowGet);
        }