public bool Update(Vacation obj) { try { _db.SubmitChanges(); } catch (Exception ex) { Debug.Print(ex.Message); return(false); } return(true); }
public bool Delete(Vacation obj) { try { _db.Vacations.DeleteOnSubmit(obj); _db.SubmitChanges(); } catch (Exception ex) { Debug.Print(ex.Message); return(false); } return(true); }
//public void SetDelete(int vacationId) //{ // var query = _db.Vacations.FirstOrDefault(x => x.VacationId == vacationId); // if (query != null) // { // _db.Vacations.DeleteOnSubmit(query); // _db.SubmitChanges(); // } //} public int Add(Vacation obj) { try { _db.Vacations.InsertOnSubmit(obj); _db.SubmitChanges(); } catch (Exception ex) { Debug.Print(ex.Message); return(-1); } return(_db.Vacations.Max(x => x.VacationId)); }
protected void RadToolBar1_ButtonClick(object sender, RadToolBarEventArgs e) { // Save if (e.Item.Text == "TempSave" || e.Item.Text == "Request") { if (IsValid) { var cObj = new CVacation(); var obj = cObj.Get(Id); // new one if (obj == null) { obj = new Erp2016.Lib.Vacation(); obj.CreatedId = Convert.ToInt32(CurrentUserId); obj.CreatedDate = DateTime.Now; int newIndex = Convert.ToInt32(cObj.Add(obj).ToString()); obj = cObj.Get(newIndex); ViewState["NewIndex"] = newIndex; } else { obj.UpdatedId = Convert.ToInt32(CurrentUserId); obj.UpdatedDate = DateTime.Now; ViewState["NewIndex"] = obj.VacationId.ToString(); } obj.ApprovalId = CurrentUserId; obj.ApprovalDate = DateTime.Now; if (e.Item.Text == "TempSave") { obj.ApprovalStatus = null; } else { var cApprovalHistory = new CApprovalHistory(); cApprovalHistory.DelApprovalHistory((int)CConstValue.Approval.Vacation, Convert.ToInt32(ViewState["NewIndex"])); // approve request var approval = new CApproval(); var approvalResult = approval.ApproveRequstCreate((int)CConstValue.Approval.Vacation, CurrentUserId, Convert.ToInt32(ViewState["NewIndex"])); if (approvalResult > 0) { obj.ApprovalStatus = approvalResult; } else { ShowMessage("Failed"); return; } new CMail().SendMail(CConstValue.Approval.Vacation, CConstValue.MailStatus.ToApproveUser, Convert.ToInt32(ViewState["NewIndex"]), string.Empty, CurrentUserId); } // data obj.VacationType = Convert.ToInt32(RadComboBoxVacationType.SelectedValue); obj.Remark = RadTextBoxRemark.Text; cObj.Update(obj); // delete CVacationDetail vacationDetailClass = new CVacationDetail(); vacationDetailClass.DeleteItemsByVacationId(obj.VacationId); // insert foreach (RadDate radDate in RadCalendar1.SelectedDates) { vacationDetailClass.Add(new VacationDetail() { CreatedId = CurrentUserId, CreatedDate = DateTime.Now, VacationId = obj.VacationId, IsFullDay = RadComboBoxDayType.SelectedValue == "1" ? true : false, Date = radDate.Date }); } // save other tables RunClientScript("Close();"); } else { ShowMessage("Failed"); } } // Revise else if (e.Item.Text == "Revise") { RunClientScript("ShowApprovalReviseWindow('" + Id + "');"); } // Approval else if (e.Item.Text == "Approve") { RunClientScript("ShowApprovalWindow('" + Id + "');"); } // Reject else if (e.Item.Text == "Reject") { RunClientScript("ShowApprovalRejectWindow('" + Id + "');"); } // Print else if (e.Item.Text == "Print") { RunClientScript("ShowPrint();"); } // Cancel else if (e.Item.Text == "Cancel") { RunClientScript("ShowApprovalCancelWindow('" + Id + "');"); } // close else if (e.Item.Text == "Close") { RunClientScript("Close();"); } }