public List <EstimationModel> DeleteEstimation(EstimationModel model) { Estimation Estimation; List <Estimation> MasterDataList; try { MasterDataList = _dbContext.Estimations.ToList(); Estimation = MasterDataList.Find(item => item.ID == model.ID); if (Estimation != null) { //Estimation.IsDeleted = true; _dbContext.Entry(Estimation).State = EntityState.Modified; _dbContext.SaveChanges(); } } catch (Exception ex) { IErrorLogService errorLog = new ErrorLogService(); string message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; errorLog.SetErrorLog(model.CurrentUserID, "Estimation", message); throw new Exception(message); } BaseModel.CurrentCulture = model.CurrentCulture; BaseModel.CurrentUserID = model.CurrentUserID; return(GetAllEstimationList(BaseModel)); }
public bool Save(CommonModelHelper model) { var isSuccess = true; try { var culturalItems = new List <string> { "CoordinatorPrecautions", "CoordinatorNotes", "NotesToStaff", "ComplainDetails", "AccountingRelatedMemo" }; ModelBinder.SetCulturalValue(model.Order, model, culturalItems); model.Order.ApplicationID = model.ApplicationID; model.Order.OrderStatus = (int)OrderStatus.Ordered; //Save Order if (model.Order.ID == Guid.Empty) { model.Order.ID = Guid.NewGuid(); model.Order.InvoiceNo = GenerateInvoiceNo(); model.Order.Estimation = _dbContext.Estimations.Find(model.Estimation.ID); model.Order.OrderNo = GenerateOrderNo(); model.Order.CompanyID = model.Estimation.ClientID; model.Order.Company = _dbContext.Companies.Find(model.Order.CompanyID); _dbContext.Orders.Add(model.Order); } else { _dbContext.Entry(model.Order).State = EntityState.Modified; } //Save or update Order details foreach (var item in model.OrderDetails) { item.OrderID = model.Order.ID; item.Order = model.Order; ModelBinder.ModifyGuidValue(item); if (item.ID == Guid.Empty) { item.ID = Guid.NewGuid(); _dbContext.OrderDetails.Add(item); } else { _dbContext.Entry(item).State = EntityState.Modified; } } //Update Estimation //_dbContext.Entry(model.Estimation).State = EntityState.Modified; _dbContext.SaveChanges(); } catch (Exception ex) { isSuccess = false; IErrorLogService errorLog = new ErrorLogService(); string message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; errorLog.SetErrorLog(model.CurrentUserID, "OrderDetails", message); throw new Exception(message); } return(isSuccess); }
public bool Save(CommonModelHelper model) { var isSuccessful = true; try { var culturalItems = new List <string> { "BillingAddress", "ClientAddress", "BillingCompanyName", "DeliveryCompanyName", "DeliveryAddress", "Remarks" }; ModelBinder.SetCulturalValue(model.Estimation, model, culturalItems); model.Estimation.EstimationNo = GenerateEstimationNumber(model.ApplicationID); model.Estimation.EstimationType = (int)EstimationType.OverheadCost; model.Estimation.EstimationStatus = (int)EstimationStatus.Ordered; ModelBinder.ModifyGuidValue(model.Estimation); //cmd.Parameters.AddWithValue("@ProjectID", DBNull.Value); if (model.Estimation.ID == Guid.Empty) { model.Estimation.ID = Guid.NewGuid(); model.Estimation.RegistrationDate = DateTime.Now; _dbContext.Estimations.Add(model.Estimation); } else { _dbContext.Entry(model.Estimation).State = EntityState.Modified; } //Save or update Estimation details model.EstimationDetails.ForEach(item => { item.EstimationID = model.Estimation.ID; ModelBinder.ModifyGuidValue(item); if (item.ID == Guid.Empty) { item.ID = Guid.NewGuid(); _dbContext.EstimationDetails.Add(item); } else { _dbContext.Entry(item).State = EntityState.Modified; } }); _dbContext.SaveChanges(); } catch (Exception ex) { isSuccessful = false; IErrorLogService errorLog = new ErrorLogService(); string message = ex.InnerException != null ? ex.InnerException.InnerException.Message : ex.Message; errorLog.SetErrorLog(model.CurrentUserID, "OverheadCostQuotation", message); throw new Exception(message); } return(isSuccessful); }
public bool Save(CommonModelHelper model) { bool isSuccessful = true; try { var culturalItems = new List <string> { "ActionDetails" }; ModelBinder.SetCulturalValue(model.EstimationAction, model, culturalItems); model.EstimationAction.OperationDate = DateTime.Now; model.EstimationAction.Estimation = _dbContext.Estimations.Find(model.EstimationAction.EstimationID); if (model.EstimationAction.ID == Guid.Empty) { model.EstimationAction.ID = Guid.NewGuid(); _dbContext.EstimationActions.Add(model.EstimationAction); } else { _dbContext.Entry(model.EstimationAction).State = EntityState.Modified; } _dbContext.SaveChanges(); } catch (Exception ex) { isSuccessful = false; IErrorLogService errorLog = new ErrorLogService(); string message = ex.InnerException != null ? ex.InnerException.InnerException.Message : ex.Message; errorLog.SetErrorLog(model.CurrentUserID, "EstimationAction", message); throw new Exception(message); } return(isSuccessful); }
public bool UpdateNotificationsAsRead(BaseViewModel model) { var flag = true; try { var user = _dbContext.UserInformations.Find(model.CurrentUserID); var approveStatus = (int)EstimationApprovalStatus.Approved; var readStatus = (int)EstimationApprovalStatus.Approved; var items = _dbContext.EstimationApprovals.Where(x => x.ApproverID == user.EmployeeID && x.Status != approveStatus && x.Status != readStatus).ToList(); items.ForEach(item => { item.Status = (int)EstimationApprovalStatus.Read; _dbContext.Entry(item).State = EntityState.Modified; }); _dbContext.SaveChanges(); } catch (Exception ex) { flag = false; IErrorLogService errorLog = new ErrorLogService(); string message = ex.InnerException != null ? ex.InnerException.InnerException.Message : ex.Message; errorLog.SetErrorLog(model.CurrentUserID, "UpdateNotificationsAsRead", message); throw new Exception(ex.Message); } return(flag); }
public bool SaveNarration(NarrationCommon narrationCommon) { var isSuccessful = true; Staff_NarrationInformation staffNarrationInformation = null; Staff_NarrationVoiceFiles staffNarrationVoiceFiles = null; try { if (narrationCommon.NarrationInformationModel != null) { staffNarrationInformation = Mapper.Map <NarrationInformationModel, Staff_NarrationInformation>(narrationCommon.NarrationInformationModel); if (staffNarrationInformation.ID == Guid.Empty) { staffNarrationInformation.ID = Guid.NewGuid(); staffNarrationInformation.CreatedBy = narrationCommon.NarrationInformationModel.CurrentUserID; staffNarrationInformation.CreatedDate = DateTime.Now; _dbContext.Staff_NarrationInformation.Add(staffNarrationInformation); } else { staffNarrationInformation.UpdatedBy = narrationCommon.NarrationInformationModel.CurrentUserID; staffNarrationInformation.UpdatedDate = DateTime.Now; _dbContext.Entry(staffNarrationInformation).State = EntityState.Modified; } } if (narrationCommon.NarrationVoiceFilesModel != null) { staffNarrationVoiceFiles = Mapper.Map <NarrationVoiceFilesModel, Staff_NarrationVoiceFiles>(narrationCommon.NarrationVoiceFilesModel); if (staffNarrationVoiceFiles.ID == Guid.Empty) { staffNarrationVoiceFiles.ID = Guid.NewGuid(); staffNarrationVoiceFiles.CreatedBy = narrationCommon.NarrationVoiceFilesModel.CurrentUserID; staffNarrationVoiceFiles.CreatedDate = DateTime.Now; _dbContext.Staff_NarrationVoiceFiles.Add(staffNarrationVoiceFiles); } else { staffNarrationVoiceFiles.UpdatedBy = narrationCommon.NarrationVoiceFilesModel.CurrentUserID; staffNarrationVoiceFiles.UpdatedDate = DateTime.Now; _dbContext.Entry(staffNarrationVoiceFiles).State = EntityState.Modified; } } _dbContext.SaveChanges(); } catch (Exception ex) { isSuccessful = false; IErrorLogService errorLog = new ErrorLogService(); string message = ex.InnerException != null ? ex.InnerException.InnerException.Message : ex.Message; errorLog.SetErrorLog(narrationCommon.NarrationInformationModel.CreatedBy.Value, "staffTRExperience", message); throw new Exception(message); } return(isSuccessful); }
public bool SaveTranscriptionEstimation(CommonModelHelper_Transcription model) { var isSuccessful = true; try { var culturalItems = new List <string> { "BillingAddress", "ClientAddress", "BillingCompanyName", "DeliveryCompanyName", "DeliveryAddress", "Remarks", "CoordinatorNotes", "QuotationNotes" }; ModelBinder.SetCulturalValue(model.Estimation, model, culturalItems); model.Estimation.EstimationNo = GenerateEstimationNumber(model.ApplicationID); model.Estimation.EstimationType = (int)EstimationType.Transcription; if (model.Estimation.EstimationStatus == 0) { model.Estimation.EstimationStatus = (int)EstimationStatus.Ordered; } ModelBinder.ModifyGuidValue(model.Estimation); //cmd.Parameters.AddWithValue("@ProjectID", DBNull.Value); if (model.Estimation.ID == Guid.Empty) { model.Estimation.ID = Guid.NewGuid(); model.Estimation.RegistrationDate = DateTime.Now; _dbContext.Estimations.Add(model.Estimation); } else { //model.Estimation.FirstDeliveryDate = null; //model.Estimation.FinalDeliveryDate = null; _dbContext.Entry(model.Estimation).State = EntityState.Modified; } //Save or update Estimation details foreach (var item in model.EstimationDetails) { item.EstimationID = model.Estimation.ID; ModelBinder.ModifyGuidValue(item); if ((item.ID == Guid.Empty) && (!item.IsMarkedForDelete)) { item.ID = Guid.NewGuid(); var mapItem = Mapper.Map <EstimationDetailsModel, EstimationDetail>(item); _dbContext.EstimationDetails.Add(mapItem); } else { if ((!item.IsMarkedForDelete) && (item.ID != Guid.Empty)) { var mapItem = Mapper.Map <EstimationDetailsModel, EstimationDetail>(item); _dbContext.Entry(mapItem).State = EntityState.Modified; } if ((item.IsMarkedForDelete) && (item.ID != Guid.Empty)) { var itm = _dbContext.EstimationDetails.Find(item.ID); _dbContext.EstimationDetails.Remove(itm); } } } #region "Commented" ////Save file type //var existingFileTypes = _dbContext.EstimationDeliveryFileTypes.Where(x => x.Estimation.ID == model.Estimation.ID).ToList(); //var existingWorkContent = _dbContext.EstimationWorkContents.Where(x => x.Estimation.ID == model.Estimation.ID).ToList(); //existingFileTypes?.ForEach(eft => //{ // _dbContext.EstimationDeliveryFileTypes.Remove(eft); //}); //existingWorkContent?.ForEach(ewc => //{ // _dbContext.EstimationWorkContents.Remove(ewc); //}); //model.FileTypes?.ForEach(ft => //{ // var fileType = new EstimationDeliveryFileType // { // ID = Guid.NewGuid(), // Estimation = model.Estimation, // FileType = ft.FileType, // Version = ft.Version, // IsDeleted = false // }; // _dbContext.EstimationDeliveryFileTypes.Add(fileType); //}); ////Save work content //model.WorkContents?.ForEach(wc => //{ // var content = new EstimationWorkContent // { // ID = Guid.NewGuid(), // Estimation = model.Estimation, // WorkContent = wc.WorkContent, // IsDeleted = false // }; // _dbContext.EstimationWorkContents.Add(content); //}); #endregion "Commented" _dbContext.SaveChanges(); } catch (Exception ex) { isSuccessful = false; IErrorLogService errorLog = new ErrorLogService(); string message = ex.InnerException != null ? ex.InnerException.InnerException.Message : ex.Message; errorLog.SetErrorLog(model.CurrentUserID, "TranscriptionEstimation", message); throw new Exception(message); } return(isSuccessful); }
public bool Save(CommonModelHelper model) { var isSuccessful = true; try { var culturalItems = new List <string> { "BillingAddress", "ClientAddress", "BillingCompanyName", "DeliveryCompanyName", "DeliveryAddress", "Remarks" }; ModelBinder.SetCulturalValue(model.Estimation, model, culturalItems); model.Estimation.EstimationNo = GenerateEstimationNumber(model.ApplicationID); model.Estimation.EstimationType = (int)EstimationType.Narration; model.Estimation.EstimationStatus = (int)EstimationStatus.Ordered; ModelBinder.ModifyGuidValue(model.Estimation); //cmd.Parameters.AddWithValue("@ProjectID", DBNull.Value); if (model.Estimation.ID == Guid.Empty) { model.Estimation.ID = Guid.NewGuid(); model.Estimation.RegistrationDate = DateTime.Now; _dbContext.Estimations.Add(model.Estimation); } else { _dbContext.Entry(model.Estimation).State = EntityState.Modified; } //Save or update Estimation details foreach (var item in model.EstimationDetails) { item.EstimationID = model.Estimation.ID; ModelBinder.ModifyGuidValue(item); if (item.ID == Guid.Empty) { item.ID = Guid.NewGuid(); _dbContext.EstimationDetails.Add(item); } else { _dbContext.Entry(item).State = EntityState.Modified; } } //Save file type var existingWorkContent = _dbContext.EstimationWorkContents.Where(x => x.Estimation.ID == model.Estimation.ID).ToList(); existingWorkContent?.ForEach(ewc => { _dbContext.EstimationWorkContents.Remove(ewc); }); //Save work content model.WorkContents?.ForEach(wc => { var content = new EstimationWorkContent { ID = Guid.NewGuid(), Estimation = model.Estimation, WorkContent = wc.WorkContent, IsDeleted = false }; _dbContext.EstimationWorkContents.Add(content); }); model.estimationCompetencies?.ForEach(ec => { var content = new EstimationCompetency { ID = Guid.NewGuid(), Estimation = model.Estimation, CompetencyType = ec.CompetencyType, CompetencyDetail = ec.CompetencyDetail }; _dbContext.EstimationCompetencies.Add(content); }); if (model.EstimationNarrationExpense.ID == Guid.Empty) { model.EstimationNarrationExpense.ID = Guid.NewGuid(); model.EstimationNarrationExpense.EstimationID = model.Estimation.ID; _dbContext.EstimationNarrationExpenses.Add(model.EstimationNarrationExpense); } else { _dbContext.Entry(model.EstimationNarrationExpense).State = EntityState.Modified; } _dbContext.SaveChanges(); } catch (Exception ex) { isSuccessful = false; IErrorLogService errorLog = new ErrorLogService(); string message = ex.InnerException != null ? ex.InnerException.InnerException.Message : ex.Message; errorLog.SetErrorLog(model.CurrentUserID, "NarrationEstimation", message); throw new Exception(message); } return(isSuccessful); }
public void ProcessDevTimeSync() { try { //Log time // System.Windows.Application.Current.Dispatcher.BeginInvoke((Action)(() => //{ // _MainWindow.LogText.AppendText("\n\n" + DateTime.Now.ToString() + " Process Hik Cam for Ip " + strIp + " Started ..." + _nCount.ToString()); //})); // OperationLogs.AddLog("Process Hik Cam for Ip " + strIp + " Started ... " + _nCo.ToString() + " " + _nCount.ToString()); try { _ConnectionTimeOut = Int32.Parse(ConnectTimeOut);// *1000; } catch (Exception ex) { InsertBrokerOperationLog.AddProcessLog("Error _ConnectionTimeOut ..." + ex.Message); } System.Net.Sockets.TcpClient clientSocket = new System.Net.Sockets.TcpClient(); var result = clientSocket.BeginConnect(strIp, 554, null, null); var success = result.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(_ConnectionTimeOut));//TimeSpan.FromSeconds(50)); if (success) { try { _hikContime = uint.Parse(HikConnectTime) * 1000; } catch (Exception ex) { } CHCNetSDK.NET_DVR_SetConnectTime(_hikContime, 1);//10000, 1); Int32 DVRPortNumber = nPort; m_lUserID = CHCNetSDK.NET_DVR_Login_V30(strIp, DVRPortNumber, strUserName, strPassword, ref m_struDeviceInfo); if (m_lUserID == -1) { //Login failed //Log message... strIp Camera login failed InsertBrokerOperationLog.AddProcessLog(strIp + " :Login failed ..."); StopInterface(); return; } else { InsertBrokerOperationLog.AddProcessLog(strIp + " :Login Success ..."); } CHCNetSDK.NET_DVR_TIME CurTime; CurTime.dwYear = uint.Parse(DateTime.Now.Year.ToString()); CurTime.dwMonth = uint.Parse(DateTime.Now.Month.ToString()); CurTime.dwDay = uint.Parse(DateTime.Now.Day.ToString()); CurTime.dwHour = uint.Parse(DateTime.Now.Hour.ToString()); CurTime.dwMinute = uint.Parse(DateTime.Now.Minute.ToString()); CurTime.dwSecond = uint.Parse(DateTime.Now.Second.ToString()); IntPtr pnt = Marshal.AllocHGlobal(Marshal.SizeOf(CurTime)); try { // Copy the struct to unmanaged memory. Marshal.StructureToPtr(CurTime, pnt, false); uint _size = (uint)Marshal.SizeOf(CurTime); var IsTimeSet = CHCNetSDK.NET_DVR_SetDVRConfig(m_lUserID, CHCNetSDK.NET_DVR_SET_TIMECFG, 0, pnt, _size); if (IsTimeSet == true) { //Log message......Successfuly Time Sync strIp Camera try { using (var ctx = new CentralDBEntities()) { var tblDeviceSync = ctx.tblTimeSyncinfo.FirstOrDefault(x => x.DeviceID == _deviceID); tblDeviceSync.DateTimeSyncStatus = 1; ctx.Entry(tblDeviceSync).State = System.Data.EntityState.Modified; ctx.SaveChanges(); } } catch (Exception ex) { } InsertBrokerOperationLog.AddProcessLog("Successfuly Time Sync: " + strIp + " Camera ..."); } else { //Log message......Failed Time Sync strIp Camera . try { using (var ctx = new CentralDBEntities()) { var tblDeviceSync = ctx.tblTimeSyncinfo.FirstOrDefault(x => x.DeviceID == _deviceID); tblDeviceSync.DateTimeSyncStatus = 0; ctx.Entry(tblDeviceSync).State = System.Data.EntityState.Modified; ctx.SaveChanges(); } } catch (Exception ex) { } InsertBrokerOperationLog.AddProcessLog("Failed Time Sync: " + strIp + " Camera ..."); } StopInterface(); clientSocket.EndConnect(result); } catch (Exception ex) { InsertBrokerOperationLog.AddProcessLog("Error ProcessDevTimeSync NET_DVR_SetDVRConfig ..." + ex.Message); } finally { // Free the unmanaged memory. Marshal.FreeHGlobal(pnt); } } else { InsertBrokerOperationLog.AddProcessLog(strIp + " :Camera is offline"); //Log message... strIp Camera is offline } } catch (Exception ex) { InsertBrokerOperationLog.AddProcessLog("Error ProcessDevTimeSync ..." + ex.Message); MessageBox.Show("Error ProcessDevTimeSync ..." + ex.Message); } //System.Windows.Application.Current.Dispatcher.BeginInvoke((Action)(() => //{ // _MainWindow.LogText.AppendText("\n\n" + DateTime.Now.ToString() + " Process Hik Cam for Ip " + strIp + " End ..." + _nCount.ToString()); //})); // OperationLogs.AddLog("Process Hik Cam for Ip " + strIp + " End ... " + _nCo.ToString() + " " + _nCount.ToString()); }