public async Task <ActionResult <TblGroup> > PostTblGroup(TblGroup tblGroup) { _context.TblGroup.Add(tblGroup); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTblGroup", new { id = tblGroup.IdGroup }, tblGroup)); }
/// <summary> /// Author: Phạm Huy Hùng /// Todo: cập nhật đối tượng /// </summary> /// <param name=""></param> /// <returns></returns>\ public void Update(TblGroup o) { try { using (TkSchoolDbContext db = new TkSchoolDbContext()) { var res = db.TblGroups.Where(x => x.GroupId == o.GroupId).Single(); res.Name = o.Name; res.Status = o.Status; res.Description = o.Description; db.SaveChanges(); } } catch (Exception ex) { if (ex.InnerException == null) { throw new Exception("TblGroupDao::Update::" + ex.Message); } else { throw new Exception("TblGroupDao::Update::" + ex.InnerException.Message); } } }
public async Task <IActionResult> PutTblGroup(int id, TblGroup tblGroup) { if (id != tblGroup.IdGroup) { return(BadRequest()); } _context.Entry(tblGroup).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TblGroupExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
protected void btnDelete_Click(object sender, EventArgs e) { LinkButton GroupID = (LinkButton)sender; TblGroup.Delete(GroupID.CommandArgument); lblmsg.Text = helper.DisplayNotificationMessage(msgDiv, "Group has been deleted permanently", "alert alert-danger alert-icon alert-dismissible", icon, "icon mdi mdi-close-circle-o"); BindGroups(); }
public ActionResult Save(GroupViewModel groupViewModel) { try { if (ModelState.IsValid) { //add if (groupViewModel.GroupId == 0 && groupViewModel.ActionName == "Add") { var model = new TblGroup() { GroupId = groupViewModel.GroupId, GroupName = groupViewModel.GroupName, Description = groupViewModel.Description, //ApplicationId = groupViewModel.ApplicationId, //ModuleId = groupViewModel.ModuleId }; //_groupRepository.Insert(model); //add role to group wise } else if (groupViewModel.ActionName == "Edit") //edit { TblGroup group = _groupRepository.GetById(groupViewModel.GroupId); if (group != null) { group.GroupId = groupViewModel.GroupId; group.GroupName = groupViewModel.GroupName; group.Description = groupViewModel.Description; //group.ApplicationId = groupViewModel.ApplicationId; //group.ModuleId = groupViewModel.ModuleId; //_groupRepository.Update(group); } else { return(Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.FalseString, groupViewModel.ActionName, MessageType.warning.ToString(), ExceptionHelper.ExceptionMessageForNullObject()))); } } //_groupRepository.Save(); return(Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.TrueString, groupViewModel.ActionName, MessageType.success.ToString(), "Saved Successfully."))); } return(Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.FalseString, groupViewModel.ActionName, MessageType.warning.ToString(), ExceptionHelper.ModelStateErrorFormat(ModelState)))); } catch (Exception ex) { return(Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.FalseString, groupViewModel.ActionName, MessageType.warning.ToString(), ExceptionHelper.ExceptionMessageFormat(ex)))); } }
protected void btnEdit_Click(object sender, EventArgs e) { LinkButton GroupID = (LinkButton)sender; TblGroup obj = new TblGroup(GroupID.CommandArgument); ddlLevel.SelectedValue = obj.LevelID.ToString(); BindClasses(); ddlclass.SelectedValue = obj.ClassID.ToString(); txtGroup.Text = obj.GroupName; hfGroupID.Value = GroupID.CommandArgument; ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal();", true); }
private void LoadGroupGridView(IList <Group> arr, int selectedIndex = -1) { var table = new TblGroup(arr, true); this.gridGroup.DataSource = table; this.SetUpGroupGridView(); if (selectedIndex < 0) { this.gridGroup.ClearSelection(); } else { this.gridGroup.Rows[selectedIndex].Selected = true; } }
protected void btnAssignTo_Click(object sender, EventArgs e) { LinkButton GroupID = (LinkButton)sender; TblGroup obj = new TblGroup(GroupID.CommandArgument); if (obj.AssignTo != -1) { DataTable dt = SPs.SpGroups(obj.AssignTo, Convert.ToInt32(Session["BranchID"])).GetDataSet().Tables[0]; string DesignationID = dt.Rows[0]["DesignationID"].ToString(); ddlDesignation.SelectedValue = DesignationID; BindEmployees(DesignationID); ddlEmployees.SelectedValue = dt.Rows[0]["EmployeeID"].ToString(); } hfGroupID.Value = GroupID.CommandArgument; ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModalAssignTo();", true); }
private void LoadGroupGridView(IList <AppCore.Models.Group> arr, int selectedIndex = -1) { var table = new TblGroup(arr); this.gridViewGroup.DataSource = table; this.SetUpGroupGridView(); if (selectedIndex < 0) { this.gridViewGroup.ClearSelection(); this.EnableGroupButton(false); } else { this.gridViewGroup.Rows[selectedIndex].Selected = true; } }
protected void btnSave_Click(object sender, EventArgs e) { try { if (helper.ExecutePlainQuery("select * from tbl_Groups where GroupName='" + txtGroup.Text + "' and ClassID=" + ddlclass.SelectedValue + " and BranchID=" + Session["BranchID"]).Rows.Count > 0 && String.IsNullOrEmpty(hfGroupID.Value)) { lblmsg.Text = helper.DisplayNotificationMessage(msgDiv, txtGroup.Text + " already exists!", "alert alert-danger alert-icon alert-dismissible", icon, "icon mdi mdi-check"); } else { string msg = "Group has been added!"; TblGroup obj = new TblGroup(); obj.IsNew = true; if (!String.IsNullOrEmpty(hfGroupID.Value)) { obj.IsNew = false; obj = new TblGroup(hfGroupID.Value); msg = "Group has been updated!"; } obj.GroupName = txtGroup.Text; obj.ClassID = Convert.ToInt32(ddlclass.SelectedValue); obj.BranchID = Convert.ToInt32(Session["BranchID"]); obj.LevelID = Convert.ToInt32(ddlLevel.SelectedValue); if (obj.IsNew) { obj.AssignTo = -1; } obj.Save(); lblmsg.Text = helper.DisplayNotificationMessage(msgDiv, msg, "alert alert-success alert-icon alert-dismissible", icon, "icon mdi mdi-check"); hfGroupID.Value = null; BindGroups(); } helper.ClearInputs(Page.Controls); } catch (Exception ex) { lblmsg.Text = helper.DisplayNotificationMessage(msgDiv, ex.ToString(), "alert alert-danger alert-icon alert-dismissible", icon, "icon mdi mdi-close-circle-o"); } }
/// <summary> /// Author: Phạm Huy Hùng /// Todo: tìm kiếm đối tượng theo khóa chính /// </summary> /// <param name="obj"></param> /// <returns></returns> public TblGroup FindById(TblGroup obj) { try { using (TkSchoolDbContext db = new TkSchoolDbContext()) { return(db.TblGroups.SingleOrDefault(x => x.GroupId == obj.GroupId)); } } catch (Exception ex) { if (ex.InnerException == null) { throw new Exception("TblGroupDao::FindById::" + ex.Message); } else { throw new Exception("TblGroupDao::FindById::" + ex.InnerException.Message); } } }
/// <summary> /// Author: Phạm Huy Hùng /// Todo: tạo đối tượng mới /// </summary> /// <param name=""></param> /// <returns></returns> public void Create(TblGroup o) { try { using (TkSchoolDbContext db = new TkSchoolDbContext()) { db.TblGroups.Add(o); db.SaveChanges(); } } catch (Exception ex) { if (ex.InnerException == null) { throw new Exception("TblGroupDao::Create::" + ex.Message); } else { throw new Exception("TblGroupDao::Create::" + ex.InnerException.Message); } } }
protected void btnAssign_Click(object sender, EventArgs e) { try { if (helper.ExecutePlainQuery("select * from Tbl_Groups where GroupID='" + hfGroupID.Value + "' and AssignTo='" + ddlEmployees.SelectedValue + "' and BranchID=" + Session["BranchID"]).Rows.Count > 0) { lblmsg.Text = lblmsg.Text = helper.DisplayNotificationMessage(msgDiv, "This group already assigned to " + ddlEmployees.SelectedItem.Text + "!", "alert alert-danger alert-icon alert-dismissible", icon, "icon mdi mdi-close-circle-o"); } else { TblGroup obj = new TblGroup(hfGroupID.Value); obj.AssignTo = Convert.ToInt16(ddlEmployees.SelectedValue); obj.IsNew = false; obj.Save(); lblmsg.Text = helper.DisplayNotificationMessage(msgDiv, "Group " + obj.GroupName + " has been assigned to " + ddlEmployees.SelectedItem.Text, "alert alert-success alert-icon alert-dismissible", icon, "icon mdi mdi-check"); BindGroups(); } } catch { } }
/// <summary> /// Author: Phạm Huy Hùng /// Todo: xóa đối tượng /// </summary> /// <param name="o"></param> /// <returns></returns> public void Delete(TblGroup o) { try { using (TkSchoolDbContext db = new TkSchoolDbContext()) { var res = db.TblGroups.Where(x => x.GroupId == o.GroupId).Single(); db.TblGroups.Remove(res); db.SaveChanges(); } } catch (Exception ex) { if (ex.InnerException == null) { throw new Exception("TblGroupDao::Delete::" + ex.Message); } else { throw new Exception("TblGroupDao::Delete::" + ex.InnerException.Message); } } }