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();
            }
        }
Exemple #2
0
        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;
            }
        }
Exemple #3
0
 public void UpdateSignaturePath(int nID, String signaturePath)
 {
     CrmtOrder order = null;
     using (var ds = new DataService(this.connectionString, this.consumerInfo))
     {
         order = ds.CrmtOrder.GetAllNotDelete().Where(x => x.nID == nID).FirstOrDefault();
         order.sReportSignPath = signaturePath;
         order.dLastUpdate = DateTime.Now;
         ds.CrmtOrder.Update(order);
         ds.SaveChanges();
     }
 }
Exemple #4
0
        public void UpdateJob(JobDetailEditDTO model)
        {
            if (model != null)
            {
                using (var ds = new DataService(this.connectionString, this.consumerInfo))
                {
                    CrmtOrder order = ds.CrmtOrder.GetAll().Where(j => j.nID == model.nID).FirstOrDefault();
                    order.dRepairDate = model.dRepairDate;
                    if (model.nStartHour.HasValue && model.nStartMinute.HasValue && (model.nStartHour.Value != 0 || model.nStartMinute != 0))
                    {
                        order.tStartTime = new TimeSpan(model.nStartHour.Value, model.nStartMinute.Value, 0);
                    }
                    else
                    {
                        order.tStartTime = null;
                    }
                    if (model.nEndHour.HasValue && model.nEndMinute.HasValue && (model.nEndHour.Value != 0 || model.nEndMinute != 0))
                    {
                        order.tEndTime = new TimeSpan(model.nEndHour.Value, model.nEndMinute.Value, 0);
                    }
                    else
                    {
                        order.tEndTime = null;
                    }
                    order.nTechnician1ID = model.nTechnician1ID;
                    order.nTechnician2ID = model.nTechnician2ID;
                    order.nTechnician3ID = model.nTechnician3ID;
                    order.nTechnician4ID = model.nTechnician4ID;
                    order.nAdHocTechnicianID = model.nAdHocTechnicianID;

                    if (!model.bIsEcall)
                    {
                        if (model.sMaintenanceRoutine == "AY")
                        {
                            CrmtMaintenance maintenanceRecord = (from m in ds.CrmtMaintenance.GetAll()
                                                                 join r in ds.CrmtTableRelation.GetAll() on m.nID equals r.nTable1ID
                                                                 where r.sTable1 == "maintenance" && r.sTable2 == "order" && r.nTable2ID == order.nID
                                                                 select m).FirstOrDefault();

                            DateTime? contractYearStart = maintenanceRecord.dStartDate;
                            DateTime? contractYearNext = contractYearStart.Value.AddYears(1);

                            while (contractYearStart.Value <= maintenanceRecord.dEndDate.Value)
                            {
                                if (order.dRepairDate.Value >= contractYearStart.Value && order.dRepairDate.Value < contractYearNext.Value)
                                    break;

                                contractYearStart = contractYearStart.Value.AddYears(1);
                                contractYearNext = contractYearNext.Value.AddYears(1);
                            }

                            CrmtOrder originalAYorder = (from o in ds.CrmtOrder.GetAll()
                                                         join r in ds.CrmtTableRelation.GetAll() on o.nID equals r.nTable2ID
                                                         where r.sTable1 == "maintenance" && r.sTable2 == "order"
                                                         && r.nTable1ID == maintenanceRecord.nID
                                                         && o.sRoutineTermCode == "AY" && o.nID != order.nID
                                                         && o.dRepairDate.Value >= contractYearStart && o.dRepairDate.Value < contractYearNext
                                                         select o).FirstOrDefault();

                            if (originalAYorder != null)
                            {
                                string sRoutineID = maintenanceRecord.nRoutineID.ToString();
                                originalAYorder.sRoutineTermCode = (from op in ds.CrmmWomOption.GetAll() where op.sTypeCode == "MROC" && op.sKey == sRoutineID select op.sValue).FirstOrDefault();
                                originalAYorder.dLastUpdate = DateTime.Now;
                                originalAYorder.nUpdateUserID = UserInfo.Instance.UserID;
                            }

                        }
                        order.sRoutineTermCode = model.sMaintenanceRoutine;
                    }

                    order.dLastUpdate = DateTime.Now;
                    order.nUpdateUserID = UserInfo.Instance.UserID;

                    ds.SaveChanges();
                }
            }
        }
Exemple #5
0
        public void PutApiEditJob(int nID, JobUploadApiDTO job)
        {
            using (var ds = new DataService(this.connectionString, this.consumerInfo))
            {
                CrmtOrder jobOrder = null;
                try
                {
                    jobOrder = ds.CrmtOrder.GetAllNotDelete().Where(x => x.nID == nID).FirstOrDefault();

            //        \{         # Escaped curly parentheses, means "starts with a '{' character"
            //        (          # Parentheses in a regex mean "put (capture) the stuff
            //                   #     in between into the Groups array"
            //           [^}]    # Any character that is not a '}' character
            //           *       # Zero or more occurrences of the aforementioned "non '}' char"
            //        )          # Close the capturing group
            //        \}
                    if (jobOrder.sFault.Contains("[") && jobOrder.sFault.Contains("]") && jobOrder.nIsOrder == 1)
                    {
                        Regex sFaultRegex = new Regex(@"\[([^\]]+)\]");
                        jobOrder.sFault = sFaultRegex.Replace(job.sFault, "[完成保養]");
                    }
                    else
                    {
                        jobOrder.sFault = job.sFault;
                    }
                    jobOrder.nOrderStatus = 3;
                    jobOrder.sRemark = job.sRemark;
                    jobOrder.sReport = job.sReport;
                    jobOrder.sRepair = job.sRepair;
                    jobOrder.dCompletionDate = job.dCompletionDate;
                    jobOrder.tActualStartTime = job.tActualStartTime;
                    jobOrder.tActualEndTime = job.tActualEndTime;
                    jobOrder.nAdHocTechnicianID = job.nAdHocTechnicianID;
                    jobOrder.dReportSignDate = job.dReportSignDate;
                    jobOrder.sReportOpinion = job.sReportOpinion;
                    jobOrder.sChecklistOpinion = job.sChecklistOpinion;
                    jobOrder.sReceipt = job.sReceipt;
                    jobOrder.nLanguage = job.nLanguage;
                    jobOrder.dLastUpdate = DateTime.Now;
                    ds.CrmtOrder.Update(jobOrder);
                    ds.SaveChanges();
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
        }
        public int CreateApiQuotation(QuotationBundleApiDTO quotationBundle)
        {
            using (var ds = new DataService(this.connectionString, this.consumerInfo))
            {
                if (quotationBundle.quotation != null)
                {
                    //int? currentUserID = UserInfo.Instance.UserID;
                    DateTime now = DateTime.Now;
                    CrmmRelateCustomer relateCustomer = ds.CrmmRelateCustomer.GetAll().Where(rc => rc.nID == quotationBundle.quotation.nCustomerID).FirstOrDefault();
                    if (relateCustomer != null)
                    {
                        #region Create Relate Customer and Quotation
                        CrmmRelateCustomer quotationRelateCustomer = new CrmmRelateCustomer()
                        {
                            nRawCustomerID = relateCustomer.nRawCustomerID,
                            nGroupID = relateCustomer.nGroupID,
                            nCustomerType = relateCustomer.nCustomerType,
                            nRelateType = 3,  //Quotation
                            sPrefix = relateCustomer.sPrefix,
                            nCode = relateCustomer.nCode,
                            sManualInputCode = relateCustomer.sManualInputCode,
                            sCustomerCode = relateCustomer.sCustomerCode,
                            sRefNumber = relateCustomer.sRefNumber,
                            sCenter = relateCustomer.sCenter,
                            nMailingDistrictID = relateCustomer.nMailingDistrictID,
                            nWorkingDistrictID = relateCustomer.nWorkingDistrictID,
                            nTitle = relateCustomer.nTitle,
                            sName = relateCustomer.sName,
                            sChiName = relateCustomer.sChiName,
                            sMailingAddress = relateCustomer.sMailingAddress,
                            sWorkingAddress = relateCustomer.sWorkingAddress,
                            sContactPersonName = relateCustomer.sContactPersonName,
                            sPhoneNumber1 = relateCustomer.sPhoneNumber1,
                            sPhoneNumber2 = relateCustomer.sPhoneNumber2,
                            sFaxNumber1 = relateCustomer.sFaxNumber1,
                            sFaxNumber2 = relateCustomer.sFaxNumber2,
                            sEmail = relateCustomer.sEmail,
                            Quotations = new List<CrmtQuotation>()
                        };

                        CrmtQuotation newQuotation = new CrmtQuotation
                        {
                            //sACQNumber = string.IsNullOrEmpty(quotation.sACQNumber) ? null : quotation.sACQNumber.Trim(),
                            dIssueDate = now,
                            nLanguage = 1,
                            nStatus = 1,
                            dCreateDate = now,
                            dLastUpdate = now,
                            nUpdateUserID = quotationBundle.quotation.nUserID
                        };
                        quotationRelateCustomer.Quotations.Add(newQuotation);
                        ds.CrmmRelateCustomer.Add(quotationRelateCustomer);
                        ds.SaveChanges();   //for getting quotation id
                        #endregion Create Relate Customer and Quotation

                        #region Create Relate Quotation and Order
                        int orderID = ds.CrmtOrder.GetAll().Where(o => o.nCustomerID == relateCustomer.nID).Select(o => o.nID).FirstOrDefault();
                        CrmtTableRelation relateQuotationOrder = new CrmtTableRelation
                        {
                            sTable1 = "quotation",
                            sTable2 = "order",
                            nTable1ID = newQuotation.nID,
                            nTable2ID = orderID
                        };
                        ds.CrmtTableRelation.Add(relateQuotationOrder);
                        ds.SaveChanges();
                        #endregion Create Relate Quotation and Order

                        #region Create Quotation Items
                        if (quotationBundle.quotationItems != null)
                        {
                            int itemSequence = 1;
                            foreach (QuotationItemApiDTO quotationItem in quotationBundle.quotationItems)
                            {
                                //Get Quotation Package Item
                                List<CrmmQuotationPackageItem> packageItems = (from qpi in ds.CrmmQuotationPackageItem.GetAll()
                                                                             where qpi.nQuotationPackageID == quotationItem.nQuotationPackageID & qpi.nStatus == 1
                                                                             orderby qpi.nSequence
                                                                             select qpi).ToList();
                                foreach (CrmmQuotationPackageItem packageItem in packageItems)
                                {
                                    #region Create Quotation Item
                                    CrmtQuotationItem newQuotationItem = new CrmtQuotationItem
                                    {
                                        sCode = packageItem.sCode,
                                        nSequence = itemSequence,
                                        sDetailChi = packageItem.sDetailChi,
                                        sDetailEng = packageItem.sDetailEng,
                                        nPrice = packageItem.nPrice,
                                        dLastUpdate = now,
                                        nUpdateUserID = quotationBundle.quotation.nUserID
                                    };
                                    ds.CrmtQuotationItem.Add(newQuotationItem);
                                    ds.SaveChanges();   //for getting quotation item id
                                    #endregion Create Quotation Item

                                    #region Create Quotation Item Relate Record
                                    CrmtTableRelation relation = new CrmtTableRelation
                                    {
                                        sTable1 = "quotation",
                                        sTable2 = "quotation_items",
                                        nTable1ID = newQuotation.nID,
                                        nTable2ID = newQuotationItem.nID
                                    };
                                    ds.CrmtTableRelation.Add(relation);
                                    ds.SaveChanges();
                                    #endregion Create Quotation Item Relate Record

                                    itemSequence++;
                                }
                            }
                        }
                        return quotationRelateCustomer.Quotations.FirstOrDefault().nID;

                        #endregion Create Quotation Items
                    }

                }
                return -1;
            }
        }
 public void UpdateQuotationSignature(int quotationID, string imageFilePath)
 {
     using (var ds = new DataService(this.connectionString, this.consumerInfo))
     {
         CrmtQuotation quotation = ds.CrmtQuotation.GetAll().Where(q => q.nID == quotationID).FirstOrDefault();
         if (quotation != null)
         {
             quotation.sCustomerSignPath = imageFilePath;
             quotation.dConfirmDate = DateTime.Today;
             quotation.dLastUpdate = DateTime.Now;
             quotation.nUpdateUserID = 33;
             ds.CrmtQuotation.Update(quotation);
             ds.SaveChanges();
         }
     }
 }
        private void HttpPostAckToGCM(CrmmUser ctrmUser, RecipientAck recipientAck, DataService ds)
        {
            try
            {
                //bool result = false;
                StringBuilder returnStr = new StringBuilder();

                string[] regIDs = new string[1];
                regIDs[0] = ctrmUser.sCloudID;

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://android.googleapis.com/gcm/send");
                request.Method = "POST";
                request.ContentType = "application/json;charset=utf-8;";
                request.Headers.Add(string.Format("Authorization: key={0}", GCM_SERVER_API_KEY));
                request.Timeout = 10000;
                var postData = new
                {
                    data = new
                    {
                        recipientAck = new
                        {
                            recipientID = recipientAck.recipientID,
                            dAckDate = recipientAck.dAckDate

                        }
                    },
                    registration_ids = regIDs
                };
                string p = JsonConvert.SerializeObject(postData);//convert the linq to json string
                byte[] byteArray = Encoding.UTF8.GetBytes(p);//convert to string to be sent to byte[]
                request.ContentLength = byteArray.Length;

                Stream dataStream = request.GetRequestStream();
                dataStream.Write(byteArray, 0, byteArray.Length);
                dataStream.Close();

                //send request
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                //response.StatusCode = HttpStatusCode.OK
                Stream responseStream = response.GetResponseStream();
                StreamReader reader = new StreamReader(responseStream);
                string responseStr = reader.ReadToEnd();

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    GcmResponse gcmResponse = (GcmResponse)JsonConvert.DeserializeObject<GcmResponse>(responseStr);
                    List<GcmResponseResult> results = gcmResponse.results;

                    for (int i = 0; i < results.Count; i++)
                    {
                        GcmResponseResult gcmResponseResult = results[i];

                        if (gcmResponseResult.message_id != null)
                        {

                            if (gcmResponseResult.registration_id != null)
                                ctrmUser.sCloudID = gcmResponseResult.registration_id;
                            //update GCMID

                            ds.CrmmUser.Update(ctrmUser);
                            ds.SaveChanges();
                        }
                    }
                }

                reader.Close();
                responseStream.Close();
                response.Close();
                returnStr.Append(responseStr + "\n");

            }
            catch (WebException ex)
            {
                throw ex;
            }
            catch (NullReferenceException ex)
            {
                throw ex;
            }
        }
Exemple #9
0
        public void SetLeaves(DateTime firstDay, List<LeaveDTO> leaveModels)
        {
            using (var ds = new DataService(this.connectionString, this.consumerInfo))
            {
                #region Delete all leave in the week
                IEnumerable<CrmtLeave> notSelectedExistingLeaves = null;
                DateTime nextWeekFirstDay = firstDay.AddDays(7);
                DateTime updateTime = DateTime.Now;
                notSelectedExistingLeaves = (from l in ds.CrmtLeave.GetAllNotDelete()
                                                where l.dDate >= firstDay && l.dDate < nextWeekFirstDay
                                                select l).ToList();

                foreach (CrmtLeave notSelectedExistingLeave in notSelectedExistingLeaves)
                {
                    ds.CrmtLeave.Delete(notSelectedExistingLeave);
                }
                #endregion Delete all leave in the week

                #region Create selected leave / activate deleted leave
                if (leaveModels != null && leaveModels.Count() > 0)
                {
                    foreach (LeaveDTO leave in leaveModels)
                    {
                        CrmtLeave existingleave = (from l in ds.CrmtLeave.GetAll()
                                                   where l.nTechnicianID == leave.nTechnicianID && l.dDate == leave.dDate
                                                   select l).FirstOrDefault();
                        if (existingleave != null)
                        {
                            if (existingleave.bDelete == RecordStatus.IsDelete || existingleave.bIsAM != leave.bIsAM || existingleave.bIsPM != leave.bIsPM || existingleave.bIsFullDay != existingleave.bIsFullDay)
                            {
                                existingleave.bIsAM = leave.bIsAM;
                                existingleave.bIsPM = leave.bIsPM;
                                existingleave.bIsFullDay = leave.bIsFullDay;
                                existingleave.bDelete = RecordStatus.IsNotDelete;
                                existingleave.sUpdatedType = UpdateTypes.Update;
                                ds.CrmtLeave.Update(existingleave);
                            }
                        }
                        else
                        {
                            //Create Leave
                            CrmtLeave newLeave = new CrmtLeave();
                            newLeave.gID = Guid.NewGuid();
                            newLeave.nTechnicianID = leave.nTechnicianID;
                            newLeave.dDate = leave.dDate;
                            newLeave.bIsAM = leave.bIsAM;
                            newLeave.bIsPM = leave.bIsPM;
                            newLeave.bIsFullDay = leave.bIsFullDay;
                            ds.CrmtLeave.Add(newLeave);
                        }
                    }
                }
                #endregion Create selected leave / activate deleted leave

                ds.SaveChanges();
            }
        }
Exemple #10
0
        public void ApiPostBundle(JobFormBundleApiDTO jobFormBundle)
        {
            JobFormService jobFormService = new JobFormService(this.connectionString, this.consumerInfo);

            CrmtJobForm jobForm = null;
            CrmtJobFormSignature jobFormSignature = null;
            IEnumerable<CrmtJobFormItemValueGroup> jobFormItemValueGroups = null;
            IEnumerable<CrmtJobFormSubItemValue> jobFormSubItemValues = null;

            if (jobFormBundle.jobForm != null)
            {
                Mapper.CreateMap<JobFormDTO, CrmtJobForm>();
                jobForm = AutoMapper.Mapper.Map<CrmtJobForm>(jobFormBundle.jobForm);
            }

            if (jobFormBundle.jobFormSignature != null)
            {
                Mapper.CreateMap<JobFormSignatureDTO, CrmtJobFormSignature>();
                jobFormSignature = AutoMapper.Mapper.Map<CrmtJobFormSignature>(jobFormBundle.jobFormSignature);
            }

            if (jobFormBundle.jobFormItemValueGroups != null)
            {
                Mapper.CreateMap<JobFormItemValueGroupDTO, CrmtJobFormItemValueGroup>();
                jobFormItemValueGroups = AutoMapper.Mapper.Map<IEnumerable<CrmtJobFormItemValueGroup>>(jobFormBundle.jobFormItemValueGroups);
            }

            if (jobFormBundle.jobFormSubItemValues != null)
            {
                Mapper.CreateMap<JobFormSubItemValueDTO, CrmtJobFormSubItemValue>();
                jobFormSubItemValues = AutoMapper.Mapper.Map<IEnumerable<CrmtJobFormSubItemValue>>(jobFormBundle.jobFormSubItemValues);
            }

            using (var ds = new DataService(this.connectionString, this.consumerInfo))
            {
                if (jobFormBundle.jobFormWorkingDate != null)
                {
                    CrmtOrder dbOrder = ds.CrmtOrder.GetAllNotDelete().Where(x => x.nID == jobForm.nJobID).FirstOrDefault();
                    if (dbOrder != null && dbOrder.tActualStartTime == null && dbOrder.tActualEndTime == null)
                    {
                        if (dbOrder.sFault.Contains("[") && dbOrder.sFault.Contains("]") && dbOrder.nIsOrder == 1)
                        {
                            Regex sFaultRegex = new Regex(@"\[([^\]]+)\]");
                            dbOrder.sFault = sFaultRegex.Replace(dbOrder.sFault, "[完成保養]");
                        }

                        dbOrder.nOrderStatus = 3;
                        dbOrder.dCompletionDate = jobFormBundle.jobFormWorkingDate.dCompletionDate;
                        dbOrder.tActualStartTime = jobFormBundle.jobFormWorkingDate.tActualStartTime;
                        dbOrder.tActualEndTime = jobFormBundle.jobFormWorkingDate.tActualEndTime;
                        ds.CrmtOrder.Update(dbOrder);
                    }
                }

                if (jobForm != null)
                {
                    CrmtJobForm dbJobForm = ds.CrmtJobForm.GetAllNotDelete().Where(x => x.gID == jobForm.gID).FirstOrDefault();
                    if (dbJobForm == null)
                    {
                        ds.CrmtJobForm.Add(jobForm);
                    }
                }

                if (jobFormSignature != null)
                {
                    CrmtJobFormSignature dbJobFormSignature = ds.CrmtJobFormSignature.GetAllNotDelete().Where(x => x.gID == jobFormSignature.gID).FirstOrDefault();
                    if (dbJobFormSignature == null)
                    {
                        ds.CrmtJobFormSignature.Add(jobFormSignature);
                    }
                }

                if (jobFormItemValueGroups != null)
                {
                    foreach (CrmtJobFormItemValueGroup group in jobFormItemValueGroups)
                    {
                        CrmtJobFormItemValueGroup dbJobFormItemValueGroup = ds.CrmtJobFormItemValueGroup.GetAllNotDelete().Where(x => x.gID == group.gID).FirstOrDefault();
                        if (dbJobFormItemValueGroup == null)
                        {
                            ds.CrmtJobFormItemValueGroup.Add(group);
                        }
                    }
                }

                if (jobFormSubItemValues != null)
                {
                    foreach (CrmtJobFormSubItemValue itemValue in jobFormSubItemValues)
                    {
                        CrmtJobFormSubItemValue dbJobFormSubItemValue = ds.CrmtJobFormSubItemValue.GetAllNotDelete().Where(x => x.gID == itemValue.gID).FirstOrDefault();
                        if (dbJobFormSubItemValue == null)
                        {
                            ds.CrmtJobFormSubItemValue.Add(itemValue);
                        }
                    }
                }

                ds.SaveChanges();
            }
        }
Exemple #11
0
 public void UpdateSubItemValueVoicePath(Guid? gJobFormSubItemValueID, String voicePath)
 {
     CrmtJobFormSubItemValue jobFormSubItemValue = null;
     using (var ds = new DataService(this.connectionString, this.consumerInfo))
     {
         jobFormSubItemValue = ds.CrmtJobFormSubItemValue.GetAllNotDelete().Where(x => x.gID == gJobFormSubItemValueID).FirstOrDefault();
         jobFormSubItemValue.sValue = voicePath;
         jobFormSubItemValue.dUpdatedDate = DateTime.UtcNow;
         ds.CrmtJobFormSubItemValue.Update(jobFormSubItemValue);
         ds.SaveChanges();
     }
 }
Exemple #12
0
 public void UpdateSignaturePath(Guid? gJobFormID, String signaturePath)
 {
     CrmtJobFormSignature jobFormSignature = null;
     using (var ds = new DataService(this.connectionString, this.consumerInfo))
     {
         jobFormSignature = ds.CrmtJobFormSignature.GetAllNotDelete().Where(x => x.gJobFormID == gJobFormID).FirstOrDefault();
         jobFormSignature.sPath = signaturePath;
         jobFormSignature.dUpdatedDate = DateTime.UtcNow;
         ds.CrmtJobFormSignature.Update(jobFormSignature);
         ds.SaveChanges();
     }
 }
        private void HttpPostToGCM(List<CrmtMsgRecipient> crmtMsgRecipients, Message message, DataService ds)
        {
            //bool result = false;
            StringBuilder returnStr = new StringBuilder();

            string[] regIDs = new string[crmtMsgRecipients.Count];
            for (int i = 0; i < crmtMsgRecipients.Count; i++)
            {
                regIDs[i] = crmtMsgRecipients[i].CrmmUser.sCloudID;
            }

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://android.googleapis.com/gcm/send");
            request.Method = "POST";
            request.ContentType = "application/json;charset=utf-8;";
            request.Headers.Add(string.Format("Authorization: key={0}", GCM_SERVER_API_KEY));
            request.Timeout = 10000;
            var postData = new
            {
                data = new
                {
                    message = new
                    {
                        gID = message.gID,
                        nJobID = message.nJobID,
                        sTitle = message.sTitle,
                        sMessage = message.sMessage,
                        sMessageType = message.sMessageType,
                        bDelete = 0
                    }
                },
                registration_ids = regIDs
            };
            string p = JsonConvert.SerializeObject(postData);//convert the linq to json string
            byte[] byteArray = Encoding.UTF8.GetBytes(p);//convert to string to be sent to byte[]
            request.ContentLength = byteArray.Length;

            Stream dataStream = request.GetRequestStream();
            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();
            try
            {
                //send request
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                //response.StatusCode = HttpStatusCode.OK
                Stream responseStream = response.GetResponseStream();
                StreamReader reader = new StreamReader(responseStream);
                string responseStr = reader.ReadToEnd();

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    GcmResponse gcmResponse = (GcmResponse)JsonConvert.DeserializeObject<GcmResponse>(responseStr);
                    List<GcmResponseResult> results = gcmResponse.results;

                    for (int i = 0; i < results.Count; i++)
                    {
                        CrmtMsgRecipient msgtRecipient = crmtMsgRecipients[i];
                        GcmResponseResult gcmResponseResult = results[i];

                        if (gcmResponseResult.message_id != null)
                        {   //sucess sent
                            msgtRecipient.sStatus = "Sent";
                            msgtRecipient.bSent = true;
                            msgtRecipient.dSentDate = DateTime.UtcNow;

                            if (gcmResponseResult.registration_id != null)
                                msgtRecipient.CrmmUser.sCloudID = gcmResponseResult.registration_id;
                            //update GCMID

                            ds.CrmtMsgRecipient.Update(msgtRecipient);
                            ds.SaveChanges();

                        }
                        else if (gcmResponseResult.message_id == null && gcmResponseResult.error != null)
                        {
                            msgtRecipient.sStatus = gcmResponseResult.error;
                            if (!gcmResponseResult.error.Equals("Unavailable"))
                                msgtRecipient.bSent = true;

                            ds.CrmtMsgRecipient.Update(msgtRecipient);
                            ds.SaveChanges();
                            //error
                        }
                    }
                }
                else
                {
                    foreach (CrmtMsgRecipient msgtRecipient in crmtMsgRecipients)
                    {
                        msgtRecipient.bSent = true;
                        msgtRecipient.sStatus = response.StatusCode.ToString();
                        ds.CrmtMsgRecipient.Update(msgtRecipient);
                        ds.SaveChanges();
                    }
                }

                reader.Close();
                responseStream.Close();
                response.Close();
                returnStr.Append(responseStr + "\n");

            }
            catch (WebException ex)
            {
                throw ex;
            }
        }
Exemple #14
0
 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 void UpdateQuotationLanguageByOrderID(int nOrderID, byte nLanguage)
 {
     using (var ds = new DataService(this.connectionString, this.consumerInfo))
     {
         CrmtQuotation quotation = (from q in ds.CrmtQuotation.GetAllNotDelete()
                        join r in ds.CrmtTableRelation.GetAllNotDelete() on q.nID equals r.nTable1ID
                        join rc in ds.CrmmRelateCustomer.GetAllNotDelete() on r.nTable2ID equals rc.nID
                        join o in ds.CrmtOrder.GetAllNotDelete() on rc.nID equals o.nID
                        where r.sTable1 == "quotation" && r.sTable2 == "order" && o.nID == nOrderID
                        orderby r.nTable1ID descending
                        select q).FirstOrDefault();
         if (quotation != null)
         {
             quotation.nLanguage = nLanguage;
             quotation.dLastUpdate = DateTime.Now;
             ds.CrmtQuotation.Update(quotation);
             ds.SaveChanges();
         }
     }
 }
Exemple #16
0
 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 void SendOrderRemoveMessage(int nJobID, String sCustomerCode, String sCustomerName, DateTime? dRepairDate, List<int> nUserIDs)
        {
            if (nUserIDs.Count == 0)
                throw new ArgumentNullException();
            CrmtMsg crmtMsg = null;
            using (var ds = new DataService(this.connectionString, this.consumerInfo))
            {
                if (!String.IsNullOrEmpty(sCustomerCode) && !String.IsNullOrEmpty(sCustomerName))
                {
                    crmtMsg = addCancelOrderMessageByJobID(nJobID, sCustomerCode, sCustomerName, dRepairDate, ds);
                    addMsgRecipientByMsgIDUserIDs(crmtMsg, nUserIDs, ds);
                    ds.SaveChanges();
                }
            }

            if (crmtMsg != null)
            {
                SendMsgByMessage(crmtMsg.gID);
            }
            else
            {
                throw new ArgumentNullException();
            }
        }