public IEnumerable<GroupTechnicianDTO> GetGroupTechnicians(int groupID, string[] selectedTechnicianIDArray, DateTime? day, TimeSpan? startTime, TimeSpan? endTime) { List<GroupTechnicianDTO> groupTechnicians = new List<GroupTechnicianDTO>(); using (var ds = new DataService(this.connectionString, this.consumerInfo)) { var crmmTechnicians = (from t in ds.CrmmTechnician.GetAll() where t.nGroupID == groupID && t.bActive == true orderby t.sName select t).ToList(); if (crmmTechnicians.Count() > 0) { foreach (CrmmTechnician crmmTechnician in crmmTechnicians) { groupTechnicians.Add(new GroupTechnicianDTO { nID = crmmTechnician.nID, nGroupID = crmmTechnician.nGroupID, sName = crmmTechnician.sName, sGrade = crmmTechnician.sGrade, bIsLeave = crmmTechnician.isLeave(day, startTime, endTime), bIsSelected = (selectedTechnicianIDArray != null) ? selectedTechnicianIDArray.Contains(crmmTechnician.nID.ToString()) : false }); } } return groupTechnicians; } }
public IEnumerable<QuotationPackageItemApiDTO> GetQuotationPackageItemByUserID(int userID, DateTime? UpdatedAfter) { using (var ds = new DataService(this.connectionString, this.consumerInfo)) { try { var quotationPackageItemApiDTOs = from p in ds.CrmmQuotationPackageItem.GetAll().Where(x => x.dUpdateDate > UpdatedAfter) select new QuotationPackageItemApiDTO { nID = p.nID, nQuotationPackageID = p.nQuotationPackageID, nSequence = p.nSequence, sCode = p.sCode, sDetailChi = p.sDetailChi, sDetailEng = p.sDetailEng, nPrice = p.nPrice, bDelete = p.nStatus==1?false:true, dUpdatedDate = p.dUpdateDate.Value }; return quotationPackageItemApiDTOs.ToList(); } catch (Exception exception) { throw exception; } } }
public IEnumerable<HolidayApiDTO> GetHolidayByUserID(int userID, DateTime? UpdatedAfter) { List<HolidayApiDTO> holidayDTOs = new List<HolidayApiDTO>(); HolidayApiDTO holiday = null; using (var ds = new DataService(this.connectionString, this.consumerInfo)) { try { DateTime oneMonthBefore = UpdatedAfter.Value.AddMonths(-1); IEnumerable<CrmmHoliday> holidays = ds.CrmmHoliday.GetAll().Where(x => x.dDate > oneMonthBefore).ToList(); foreach (CrmmHoliday theHoliday in holidays) { holiday = new HolidayApiDTO { nID = theHoliday.nID, sTitle = theHoliday.sTitle, dDate = theHoliday.dDate, bDelete = theHoliday.nStatus==1?false:true }; holidayDTOs.Add(holiday); } return holidayDTOs; } catch (Exception exception) { throw exception; } } }
public IEnumerable<FormApiDTO> GetFormByUserID(int userID, DateTime? UpdatedAfter) { List<FormApiDTO> formDTOs = new List<FormApiDTO>(); FormApiDTO form = null; using (var ds = new DataService(this.connectionString, this.consumerInfo)) { try { IEnumerable<CrmmForm> forms = ds.CrmmForm.GetAll().Where(x => x.dUpdatedDate > UpdatedAfter).ToList(); foreach (CrmmForm theForm in forms) { form = new FormApiDTO { gID = theForm.gID, sName = theForm.sName, sEngName = theForm.sEngName, bDelete = theForm.bDelete, dUpdatedDate = theForm.dUpdatedDate }; formDTOs.Add(form); } return formDTOs; } catch (Exception exception) { throw exception; } } }
public string GetSystemParamValueByKey(string key) { using (var ds = new DataService(this.connectionString, ConsumerInfo.System)) { var systemParam = (from sp in ds.CrmcSystemParam.GetAllNotDelete() where sp.sKey == key select sp.sValue).FirstOrDefault(); return systemParam; } }
public string GetSystemParamValueByName(string name) { using (var ds = new DataService(this.connectionString, ConsumerInfo.System)) { var systemParam = (from wsp in ds.CrmcWomSystemParam.GetAllNotDelete() where wsp.sName == name select wsp.sValue).FirstOrDefault(); return systemParam; } }
public int GetAgendaOutstandingJobCount() { int jobCount = 0; using (var ds = new DataService(this.connectionString, this.consumerInfo)) { jobCount = ds.CrmtJob.GetAll().Where(j => j.dRepairDate == null && !(j.dCompletionDate.HasValue && j.tActualStartTime.HasValue && j.tActualEndTime.HasValue)).Count(); } return jobCount; }
public bool IsTokenExpired(Guid gToken) { CrmcDeviceToken deviceToken = null; using (var ds = new DataService(this.connectionString, this.consumerInfo)) { deviceToken = (from cdt in ds.CrmcDeviceToken.GetAllNotDelete() where cdt.gToken == gToken && cdt.dExpiryDate >= DateTime.UtcNow select cdt).Distinct().FirstOrDefault(); } return deviceToken == null ? true : false; }
public bool IsValidUserToken(Guid gToken, int nUserID) { CrmcDeviceToken deviceToken = null; using (var ds = new DataService(this.connectionString, this.consumerInfo)) { deviceToken = (from dt in ds.CrmcDeviceToken.GetAllNotDelete() where dt.nUserID == nUserID && dt.gToken == gToken && dt.bDelete == false select dt).Distinct().FirstOrDefault(); } return deviceToken != null ? true : false; }
public void UpdateLanguage(int nID, byte nLanguage) { CrmtOrder order = null; using (var ds = new DataService(this.connectionString, this.consumerInfo)) { order = ds.CrmtOrder.GetAllNotDelete().Where(x => x.nID == nID).FirstOrDefault(); order.nLanguage = nLanguage; order.dLastUpdate = DateTime.Now; ds.CrmtOrder.Update(order); ds.SaveChanges(); } }
public int GetActiveCount() { using (var ds = new DataService(this.connectionString, this.consumerInfo)) { try { return ds.CrmmQuotationPackage.GetAllNotDelete().Where(x => x.nStatus == 1).ToList().Count(); } catch (Exception exception) { throw exception; } } }
public int GetActiveCount(int userID) { using (var ds = new DataService(this.connectionString, this.consumerInfo)) { try { return ds.CrmtLeave.GetAllNotDelete().Where(x => x.nTechnicianID == userID).ToList().Count(); } catch (Exception exception) { throw exception; } } }
public int GetActiveCount() { using (var ds = new DataService(this.connectionString, this.consumerInfo)) { try { return ds.CrmmForm.GetAllNotDelete().ToList().Count(); } catch (Exception exception) { throw exception; } } }
public IEnumerable<GroupDTO> GetGroups() { IEnumerable<GroupDTO> groups = null; using (var ds = new DataService(this.connectionString, this.consumerInfo)) { groups = (from g in ds.CrmmGroup.GetAll() where g.nStatus == 1 select new GroupDTO { nID = g.nID, sName = g.sName }).ToList(); return groups; } }
public UserDTO GetUserByID(int userID) { UserDTO user = null; using (var ds = new DataService(this.connectionString, this.consumerInfo)) { user = (from u in ds.CrmmUser.GetAllNotDelete() where u.nID == userID select new UserDTO { nID = u.nID, sName = u.sName }).FirstOrDefault(); return user; } }
public GroupTechnicianDTO GetGroupTechnicianByID(int technicianID) { GroupTechnicianDTO technician = null; using (var ds = new DataService(this.connectionString, this.consumerInfo)) { technician = (from t in ds.CrmmTechnician.GetAll() where t.nID == technicianID && t.bActive == true select new GroupTechnicianDTO { nID = t.nID, nGroupID = t.nGroupID, sName = t.sName, sGrade = t.sGrade }).FirstOrDefault(); return technician; } }
public Byte GetUserGroupValueByName(string name) { using (var ds = new DataService(this.connectionString, this.consumerInfo)) { var userGroupOption = (from wo in ds.CrmmWomOption.GetAll() where wo.bActive == true && wo.sTypeCode == "UG" && wo.sName == name orderby wo.nSequence select wo).FirstOrDefault(); if (!string.IsNullOrEmpty(userGroupOption.sValue)) { return Byte.Parse(userGroupOption.sValue); } else { return 1; } } }
public ServiceReportOrderDTO GetServiceReportOrderByID(int orderID) { ServiceReportOrderDTO order = null; using (var ds = new DataService(this.connectionString, this.consumerInfo)) { CrmtOrder theOrder = ds.CrmtOrder.GetAll().Where(o => o.nID == orderID).FirstOrDefault(); CrmmRelateCustomer customer = theOrder.Customer; order = new ServiceReportOrderDTO { nID = theOrder.nID, sCustomerCode = customer.sCustomerCode, sCustomerName = theOrder.nLanguage == 1 ? customer.sChiName : customer.sName, sAddress = customer.sWorkingAddress, sContactPersonName = customer.sContactPersonName, sFault = theOrder.sFault, sModel = theOrder.sModel, sRemark = theOrder.sRemark, sRepair = theOrder.sRepair, sReport = theOrder.sReport, sReviewerName = theOrder.sReviewerName, sReportSignPath = theOrder.sReportSignPath, dReportSignDate = theOrder.dReportSignDate, tStartTime = theOrder.tActualStartTime, tEndTime = theOrder.tActualEndTime, dCompletionDate = theOrder.dCompletionDate, sCustomerOpinion = theOrder.sReportOpinion, sReceipt = theOrder.sReceipt }; #region Get Technician Name String order.sTechnicianNameString = string.Empty; if (theOrder.Technician1 != null) order.sTechnicianNameString = string.Format("{0} [ {1} ]", theOrder.Technician1.sName, theOrder.Technician1.sEmployeeNumber); if (theOrder.Technician2 != null) order.sTechnicianNameString = order.sTechnicianNameString + Environment.NewLine + string.Format("{0} [ {1} ]", theOrder.Technician2.sName, theOrder.Technician2.sEmployeeNumber); if (theOrder.Technician3 != null) order.sTechnicianNameString = order.sTechnicianNameString + Environment.NewLine + string.Format("{0} [ {1} ]", theOrder.Technician3.sName, theOrder.Technician3.sEmployeeNumber); if (theOrder.Technician4 != null) order.sTechnicianNameString = order.sTechnicianNameString + Environment.NewLine + string.Format("{0} [ {1} ]", theOrder.Technician4.sName, theOrder.Technician4.sEmployeeNumber); if (theOrder.AdHocTechnician != null) order.sTechnicianNameString = order.sTechnicianNameString + Environment.NewLine + string.Format("{0} [ {1} ]", theOrder.AdHocTechnician.sName, theOrder.AdHocTechnician.sEmployeeNumber); order.sTechnicianNameString = order.sTechnicianNameString.Trim(); #endregion Get Technician Name String return order; } }
public IEnumerable<FormSectionValueGroupTitleApiDTO> GetFormSectionValueGroupTitleByUserID(int userID, DateTime? UpdatedAfter) { IEnumerable<FormSectionValueGroupTitleApiDTO> FormSectionValueGroupTitleDTOs = null; using (var ds = new DataService(this.connectionString, this.consumerInfo)) { try { IEnumerable<CrmmFormSectionValueGroupTitle> FormSectionValueGroupTitles = ds.CrmmFormSectionValueGroupTitle.GetAll().Where(x => x.dUpdatedDate > UpdatedAfter).ToList(); Mapper.CreateMap<CrmmFormSectionValueGroupTitle, FormSectionValueGroupTitleApiDTO>(); FormSectionValueGroupTitleDTOs = AutoMapper.Mapper.Map <IEnumerable<FormSectionValueGroupTitleApiDTO>>(FormSectionValueGroupTitles); return FormSectionValueGroupTitleDTOs; } catch (Exception exception) { throw exception; } } }
public void SendMsgByMessage(Guid gMsgID) { List<CrmtMsgRecipient> crmtMsgRecipients; Message message = new Message(); using (var ds = new DataService(this.connectionString, this.consumerInfo)) { CrmtMsg crmtMsg = ds.CrmtMsg.GetAllNotDelete().Where(x => x.gID == gMsgID).FirstOrDefault(); message.gID = crmtMsg.gID; message.nJobID = crmtMsg.nJobID; message.sTitle = crmtMsg.sTitle; message.sMessage = crmtMsg.sMessage; message.sMessageType = crmtMsg.sMessageType; crmtMsgRecipients = (from p in ds.CrmtMsgRecipient.GetAll() join cu in ds.CrmmUser.GetAllNotDelete() on p.nUserID equals cu.nID where p.gMsgID == crmtMsg.gID && p.bSent == false select p).ToList(); if (crmtMsgRecipients.Count > 0) HttpPostToGCM(crmtMsgRecipients, message, ds); } }
public IEnumerable<OptionApiDTO> GetOptionByUserID(int userID, DateTime? UpdatedAfter) { IEnumerable<OptionApiDTO> optionDTOs = null; using (var ds = new DataService(this.connectionString, this.consumerInfo)) { try { IEnumerable<CrmmOption> options = ds.CrmmOption.GetAll().Where(x => x.dUpdatedDate > UpdatedAfter).ToList(); Mapper.CreateMap<CrmmOption, OptionApiDTO>(); optionDTOs = AutoMapper.Mapper.Map<IEnumerable<OptionApiDTO>>(options); return optionDTOs; } catch (Exception exception) { throw exception; } } }
public UserApiDTO GetUserByVerify(string phoneNumber, string employeeNumber) { UserApiDTO user = null; using (var ds = new DataService(this.connectionString, this.consumerInfo)) { user = (from u in ds.CrmmUser.GetAllNotDelete() where u.sPhoneNumber == phoneNumber && u.sEmployeeNumber == employeeNumber select new UserApiDTO { nID = u.nID, sName = u.sName, bDelete = u.nStatus==1?false:true }).FirstOrDefault(); if (user != null) { CrmcDeviceToken deviceToken = (from dt in ds.CrmcDeviceToken.GetAllNotDelete() where dt.nUserID == user.nID && dt.bDelete == false select dt).FirstOrDefault(); if (deviceToken == null) { deviceToken = new CrmcDeviceToken { gID = Guid.NewGuid(), nUserID = user.nID, gToken = Guid.NewGuid() }; ds.CrmcDeviceToken.Add(deviceToken); ds.SaveChanges(); } user.gToken = deviceToken.gToken; } return user; } }
public void SendNewOrderMessage(int nJobID, List<int> nUserIDs) { if (nUserIDs.Count == 0) throw new ArgumentNullException(); CrmtMsg crmtMsg; using (var ds = new DataService(this.connectionString, this.consumerInfo)) { crmtMsg = addNewOrderMessageByJobID(nJobID, ds); addMsgRecipientByMsgIDUserIDs(nJobID, crmtMsg, nUserIDs, ds); //addMsgRecipientByMsgID(nJobID, crmtMsg, ds); ds.SaveChanges(); } if (crmtMsg != null) { SendMsgByMessage(crmtMsg.gID); } else { throw new ArgumentNullException(); } }
public IEnumerable<FormSubItemDTO> GetFormSubItemByUserID(int userID, DateTime? UpdatedAfter) { List<FormSubItemDTO> formSubItemDTOs = new List<FormSubItemDTO>(); FormSubItemDTO formSubItem = null; using (var ds = new DataService(this.connectionString, this.consumerInfo)) { try { IEnumerable<CrmmFormSubItem> formSubItems = ds.CrmmFormSubItem.GetAll().Where(x => x.dUpdatedDate > UpdatedAfter).ToList(); foreach (CrmmFormSubItem theFormSubItem in formSubItems) { formSubItem = new FormSubItemDTO { gID = theFormSubItem.gID, gFormItemID = theFormSubItem.gFormItemID, nSequence = theFormSubItem.nSequence, sPrefix = theFormSubItem.sPrefix, sName = theFormSubItem.sName, sEngName = theFormSubItem.sEngName, sSuffix = theFormSubItem.sSuffix, sDataType = theFormSubItem.sDataType, bDelete = theFormSubItem.bDelete, dUpdatedDate = theFormSubItem.dUpdatedDate }; formSubItemDTOs.Add(formSubItem); } return formSubItemDTOs; } catch (Exception exception) { throw exception; } } }
public IEnumerable<QuotationPackageDTO> GetQuotationPackageByUserID(int userID, DateTime? UpdatedAfter) { List<QuotationPackageDTO> quotationPackageDTOs = new List<QuotationPackageDTO>(); QuotationPackageDTO quotationPackage = null; using (var ds = new DataService(this.connectionString, this.consumerInfo)) { try { IEnumerable<CrmmQuotationPackage> quotationPackages = ds.CrmmQuotationPackage.GetAll().Where(x => x.dUpdateDate > UpdatedAfter).ToList(); foreach (CrmmQuotationPackage theQuotationPackage in quotationPackages) { quotationPackage = new QuotationPackageDTO { nID = theQuotationPackage.nID, nDistrictID = theQuotationPackage.nDistrictID, sCode = theQuotationPackage.sCode, sName = theQuotationPackage.sName, sRemark = theQuotationPackage.sRemark, nPrice = theQuotationPackage.nPrice, bDelete = theQuotationPackage.nStatus==1?false:true, dUpdatedDate = theQuotationPackage.dUpdateDate.Value, nCustomerType = theQuotationPackage.nCustomerType.HasValue?theQuotationPackage.nCustomerType.Value:0 }; quotationPackageDTOs.Add(quotationPackage); } return quotationPackageDTOs; } catch (Exception exception) { throw exception; } } }
public IEnumerable<LeaveApiDTO> GetLeaveByUserID(int userID, DateTime? UpdatedAfter) { List<LeaveApiDTO> leaveDTOs = new List<LeaveApiDTO>(); LeaveApiDTO leave = null; using (var ds = new DataService(this.connectionString, this.consumerInfo)) { try { IEnumerable<CrmtLeave> leaves = ds.CrmtLeave.GetAll().Where(x => x.nTechnicianID == userID && x.dUpdatedDate > UpdatedAfter).ToList(); foreach (CrmtLeave theLeave in leaves) { leave = new LeaveApiDTO { gID = theLeave.gID, nTechnicianID = theLeave.nTechnicianID, dDate = theLeave.dDate, bIsAM = theLeave.bIsAM, bIsPM = theLeave.bIsPM, bIsFullDay = theLeave.bIsFullDay, bDelete = theLeave.bDelete, dUpdatedDate = theLeave.dUpdatedDate }; leaveDTOs.Add(leave); } return leaveDTOs; } catch (Exception exception) { throw exception; } } }
public IEnumerable<FormSectionDTO> GetFormSectionByUserID(int userID, DateTime? UpdatedAfter) { List<FormSectionDTO> formSectionDTOs = new List<FormSectionDTO>(); FormSectionDTO formSection = null; using (var ds = new DataService(this.connectionString, this.consumerInfo)) { try { IEnumerable<CrmmFormSection> formSections = ds.CrmmFormSection.GetAll().Where(x => x.dUpdatedDate > UpdatedAfter).ToList(); foreach (CrmmFormSection theFormSection in formSections) { formSection = new FormSectionDTO { gID = theFormSection.gID, gFormID = theFormSection.gFormID, nSequence = theFormSection.nSequence, sName = theFormSection.sName, sEngName = theFormSection.sEngName, bAllowMultiple = theFormSection.bAllowMultiple.Value, bDelete = theFormSection.bDelete, dUpdatedDate = theFormSection.dUpdatedDate }; formSectionDTOs.Add(formSection); } return formSectionDTOs; } catch (Exception exception) { throw exception; } } }
public IEnumerable<int> GetPermissionsByCurrentUserID() { int? currentUserID = UserInfo.Instance.UserID; List<int> permissions = new List<int>(); using (var ds = new DataService(this.connectionString, this.consumerInfo)) { var role = (from u in ds.CrmmUser.GetAllNotDelete() join r in ds.CrmmRole.GetAll() on u.nRoleID equals r.nID where u.nID == currentUserID select r).FirstOrDefault(); string permissionString = role.sPermission; string[] permissionSplit = permissionString.Split(','); foreach (string permissionSplitWord in permissionSplit) { int permission = 0; if (int.TryParse(permissionSplitWord.Trim(), out permission)) { permissions.Add(permission); } } return permissions; } }
public void UpdateCloudID(UserApiDTO user, string cloudID) { using (var ds = new DataService(this.connectionString, this.consumerInfo)) { CrmmUser crmmUser = (from u in ds.CrmmUser.GetAllNotDelete() where u.nID == user.nID select u).FirstOrDefault(); crmmUser.sCloudID = cloudID; ds.CrmmUser.Update(crmmUser); ds.SaveChanges(); } }
public IEnumerable<TechnicianApiDTO> GetTechnicianByUserID(int userID, DateTime? UpdatedAfter) { List<TechnicianApiDTO> technicianApiDTOs = new List<TechnicianApiDTO>(); TechnicianApiDTO technician = null; using (var ds = new DataService(this.connectionString, this.consumerInfo)) { try { IEnumerable<CrmmTechnician> technicians = ds.CrmmTechnician.GetAll().Where(x => x.dUpdatedDate > UpdatedAfter).ToList(); foreach (CrmmTechnician theTechnician in technicians) { technician = new TechnicianApiDTO { nID = theTechnician.nID, sName = theTechnician.sName, bDelete = !theTechnician.bActive, dUpdatedDate = theTechnician.dUpdatedDate }; technicianApiDTOs.Add(technician); } return technicianApiDTOs; } catch (Exception exception) { throw exception; } } }