Exemple #1
0
        public JsonResult SaveDataInDatabase(StudentViewModel vObj)
        {
            var result = false;

            try
            {
                if (vObj.StudentId > 0)
                {
                    tblStudent upObj = db.tblStudents.SingleOrDefault(s => s.IsDeleted == false &&
                                                                      s.StudentId == vObj.StudentId);
                    upObj.StudentName  = vObj.StudentName;
                    upObj.Email        = vObj.Email;
                    upObj.DepartmentId = vObj.DepartmentId;
                    db.SaveChanges();
                    result = true;
                }
                else
                {
                    tblStudent obj = new tblStudent();
                    obj.StudentName  = vObj.StudentName;
                    obj.Email        = vObj.Email;
                    obj.DepartmentId = vObj.DepartmentId;
                    obj.IsDeleted    = false;
                    db.tblStudents.Add(obj);
                    db.SaveChanges();
                    result = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Exemple #2
0
        public JsonResult SaveDataInDatabase(StudentViewModel model)
        {
            bool result = false;

            try
            {
                tblStudent stu = model.StudentId > 0 ? db.tblStudents.SingleOrDefault(p => p.StudentId == model.StudentId && p.IsDeleted == false) : new tblStudent();

                stu.StudentName  = model.StudentName;
                stu.Email        = model.Email;
                stu.IsDeleted    = false;
                stu.DepartmentId = model.DepartmentId;

                if (!(model.StudentId > 0))
                {
                    db.tblStudents.Add(stu);
                }

                db.SaveChanges();
                result = true;
            }
            catch (Exception e)
            {
                throw e;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Exemple #3
0
        public JsonResult SaveDataInDatabase(StudentViewModel model)
        {
            var result = false;

            try
            {
                if (model.StudentId > 0)
                {
                    tblStudent Stu = db.tblStudents.SingleOrDefault(x => x.IsDeleted == false && x.StudentId == model.StudentId);
                    Stu.StudentName  = model.StudentName;
                    Stu.Email        = model.Email;
                    Stu.DepartmentId = model.DepartmentId;
                    db.SaveChanges();
                    result = true;
                }
                else
                {
                    tblStudent Stu = new tblStudent();
                    Stu.StudentName  = model.StudentName;
                    Stu.Email        = model.Email;
                    Stu.DepartmentId = model.DepartmentId;
                    Stu.IsDeleted    = false;
                    db.tblStudents.Add(Stu);
                    db.SaveChanges();
                    result = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
 public JsonResult SaveData(SiteUser model)
 {
     model.IsValid = false;
     db.SiteUsers.Add(model);
     db.SaveChanges();
     BuildEmailTemplate(model.ID);
     return(Json("Registration Successfull", JsonRequestBehavior.AllowGet));
 }
        public ActionResult Index(EmployeeViewModel model)
        {
            try
            {
                MVCTutorialEntities db = new MVCTutorialEntities();



                // db.SaveChanges();

                if (model.EmployeeID > 0)
                {
                    //update
                    Employee emp = db.Employees.SingleOrDefault(x => x.EmployeeID == model.EmployeeID && x.Isbool == false);
                    emp.DepartmentID = model.DepartmentID;
                    emp.Name         = model.Name;
                    emp.Address      = model.Address;
                    db.SaveChanges();
                }
                else
                {
                    //insert
                    Employee emp = new Employee();

                    emp.Name         = model.Name;
                    emp.Address      = model.Address;
                    emp.DepartmentID = model.DepartmentID;
                    emp.Isbool       = false;
                    db.Employees.Add(emp);
                    db.SaveChanges();
                }
                return(View(model));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            //return RedirectToAction("Index");
        }
        public ActionResult RegisterUser(RegistrationViewModel model)
        {
            MVCTutorialEntities db       = new MVCTutorialEntities();
            SiteUser            siteUser = new SiteUser();

            siteUser.UserName = model.UserName;
            siteUser.EmailId  = model.EmailId;
            siteUser.Password = model.Password;
            siteUser.Address  = model.Address;
            siteUser.RoleId   = 3;
            db.SiteUsers.Add(siteUser);
            db.SaveChanges();

            return(View());
        }
        public JsonResult DeleteEmp(int EmployeeID)
        {
            bool result             = false;
            MVCTutorialEntities db  = new MVCTutorialEntities();
            Employee            emp = db.Employees.SingleOrDefault(x => x.Isbool == false && x.EmployeeID == EmployeeID);

            if (emp != null)
            {
                emp.Isbool = true;
                db.SaveChanges();
                result = true;
            }


            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public ActionResult UpdateItem(string itemIds)
        {
            int        count      = 1;
            List <int> itemIdList = new List <int>();

            itemIdList = itemIds.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
            foreach (var itemId in itemIdList)
            {
                try
                {
                    Post item = db.Posts.Where(x => x.Id == itemId).FirstOrDefault();
                    item.RowNo = count;
                    db.Posts.AddOrUpdate(item);
                    db.SaveChanges();
                }
                catch (Exception) {
                    continue;
                }
                count++;
            }
            return(Json(true, JsonRequestBehavior.AllowGet));
        }