public SavingResult SaveNewRecord(tblLeaveAdjustment SaveModel) { SavingResult res = new SavingResult(); //-- Perform Validation //res.ExecutionResult = eExecutionResult.ValidationError; //res.ValidationError = "Validation error message"; //return res; //-- using (dbVisionEntities db = new dbVisionEntities()) { //tblLeaveAdjustment SaveModel; if (SaveModel.LeaveAdjustmentNo == 0) { res.ValidationError = "Please enter Leave Application No.."; res.ExecutionResult = eExecutionResult.ValidationError; return(res); } else if (IsDuplicateRecord(SaveModel.LeaveAdjustmentNoPrefixID, SaveModel.LeaveAdjustmentNo, SaveModel.LeaveAdjustmentID, db)) { res.ValidationError = "Can not accept duplicate value. The Leave Application No. is already exists."; res.ExecutionResult = eExecutionResult.ValidationError; return(res); } if (SaveModel.LeaveAdjustmentID == 0) // New Entry { SaveModel.rcuid = Model.CommonProperties.LoginInfo.LoggedinUser.UserID; SaveModel.rcdt = DateTime.Now; SaveModel.CompanyID = Model.CommonProperties.LoginInfo.LoggedInCompany.CompanyID; SaveModel.FinPeriodID = Model.CommonProperties.LoginInfo.LoggedInFinPeriod.FinPeriodID; db.tblLeaveAdjustments.Add(SaveModel); } else { SaveModel.reuid = Model.CommonProperties.LoginInfo.LoggedinUser.UserID; SaveModel.redt = DateTime.Now; db.tblLeaveAdjustments.Attach(SaveModel); db.Entry(SaveModel).State = System.Data.Entity.EntityState.Modified; } //-- try { db.SaveChanges(); res.PrimeKeyValue = SaveModel.LeaveAdjustmentID; res.ExecutionResult = eExecutionResult.CommitedSucessfuly; } catch (Exception ex) { CommonFunctions.GetFinalError(res, ex); } } return(res); }
public SavingResult DeleteRecord(long DeleteID) { SavingResult res = new SavingResult(); using (dbVisionEntities db = new dbVisionEntities()) { if (DeleteID != 0) { tblLeaveAdjustment RecordToDelete = db.tblLeaveAdjustments.FirstOrDefault(r => r.LeaveAdjustmentID == DeleteID); if (RecordToDelete == null) { res.ValidationError = "Selected record not found. May be it has been deleted by another user over network."; res.ExecutionResult = eExecutionResult.ValidationError; return(res); } else { //db.tblLeaveAdjustments.Remove(RecordToDelete); byte RecordState_Deleted = (byte)eRecordState.Deleted; RecordToDelete.rstate = RecordState_Deleted; db.tblLeaveAdjustments.Attach(RecordToDelete); db.Entry(RecordToDelete).State = System.Data.Entity.EntityState.Modified; } try { db.SaveChanges(); res.ExecutionResult = eExecutionResult.CommitedSucessfuly; } catch (Exception ex) { CommonFunctions.GetFinalError(res, ex); } } } return(res); }
public override void FillSelectedRecordInContent(object RecordToFill) { LeaveAdjustmentEditListModel EditingRecord = (LeaveAdjustmentEditListModel)RecordToFill; tblLeaveAdjustment SaveModel = DALObject.FindSaveModelByPrimeKey(EditingRecord.LeaveAdjustmentID); if (SaveModel == null) { return; } deLeaveAdjustmentDate.DateTime = SaveModel.LeaveAdjustmentDate; lookupLeaveAdjustmentNoPrefix.EditValue = SaveModel.LeaveAdjustmentNoPrefixID; txtLeaveAdjustmentNo.EditValue = SaveModel.LeaveAdjustmentNo; lookupEmployee.EditValue = SaveModel.EmployeeID; lookupLeaveType.EditValue = SaveModel.LeaveTypeID; txtNofDays.EditValue = SaveModel.NofLeaves; LeaveBalance = LeaveTypeDALObj.GetLeaveBalance(SaveModel.EmployeeID, SaveModel.LeaveTypeID, deLeaveAdjustmentDate.DateTime) - SaveModel.NofLeaves; txtRemarks.Text = SaveModel.Remarks; txtDocument.Text = SaveModel.ApplicationDocumentFileName; base.FillSelectedRecordInContent(RecordToFill); }
public override void SaveRecord(SavingParemeter Paras) { DAL.tblLeaveAdjustment SaveModel = null; if (Paras.SavingInterface == SavingParemeter.eSavingInterface.AddNew || EditRecordDataSource == null) { SaveModel = new tblLeaveAdjustment(); } else { SaveModel = DALObject.FindSaveModelByPrimeKey(((LeaveAdjustmentEditListModel)EditRecordDataSource).LeaveAdjustmentID); if (SaveModel == null) { Paras.SavingResult = new SavingResult(); Paras.SavingResult.ExecutionResult = eExecutionResult.ValidationError; Paras.SavingResult.ValidationError = "Can not edit. Selected record not found, it may be deleted by another user."; return; } } SaveModel.LeaveAdjustmentDate = deLeaveAdjustmentDate.DateTime.Date; SaveModel.LeaveAdjustmentNoPrefixID = (int)lookupLeaveAdjustmentNoPrefix.EditValue; SaveModel.LeaveAdjustmentNo = Model.CommonFunctions.ParseInt(txtLeaveAdjustmentNo.Text); SaveModel.EmployeeID = (int)lookupEmployee.EditValue; SaveModel.LeaveTypeID = (int)lookupLeaveType.EditValue; SaveModel.NofLeaves = Model.CommonFunctions.ParseDecimal(txtNofDays.Text); SaveModel.Remarks = txtRemarks.Text; // if new record or document has been changed then update it. if (Paras.SavingInterface == SavingParemeter.eSavingInterface.AddNew || SaveModel.ApplicationDocumentFileName != txtDocument.Text) { SaveModel.ApplicationDocumentFileName = null; if (!String.IsNullOrWhiteSpace(txtDocument.Text) && System.IO.File.Exists(txtDocument.Text)) { string DocumentNewPath = Path.GetFullPath(Path.Combine(CommonProperties.LoginInfo.SoftwareSettings.DocumentLocation_LeaveAdjustmentDocument)); string DocumentNewFileName = Path.Combine(DocumentNewPath, "LED" + CommonProperties.LoginInfo.LoggedInCompany.CompanyID.ToString("000") + CommonProperties.LoginInfo.LoggedInFinPeriod.FinPeriodID.ToString("000") + SaveModel.LeaveAdjustmentNo.ToString("0000000000") + Path.GetExtension(txtDocument.Text)); try { if (!Directory.Exists(DocumentNewPath)) { Directory.CreateDirectory(DocumentNewPath); } // Allow to overwrite the document only if in edit mode File.Copy(txtDocument.Text, DocumentNewFileName, (SaveModel.LeaveAdjustmentID != 0)); } catch (System.IO.IOException ex) { SavingResult res = new SavingResult(); DAL.CommonFunctions.GetFinalError(res, ex); Paras.SavingResult = res; return; } SaveModel.ApplicationDocumentFileName = DocumentNewFileName; } } Paras.SavingResult = DALObject.SaveNewRecord(SaveModel); base.SaveRecord(Paras); }