public async Task sendNotificationRequestAsync()
        {
            JPushClient client = new JPushClient(Configuration["JpushConfig:appKey"], Configuration["JpushConfig:MasterSecret"]);

            var result = from message in context.MobilePushMessage
                         where message.IsSend == false
                         select message;

            var messageList = result.ToList <MobilePushMessage>();

            foreach (MobilePushMessage message in messageList)
            {
                List <string> EmailList = new List <string>();
                /* Get email to send users */
                if (message.UserId != null)
                {
                    var userEmail = context.Personel.Where(p => p.EmpnPsl == message.UserId && p.EmailPsl != null).Select(p => p.EmailPsl).FirstOrDefault();
                    if (userEmail != null)
                    {
                        EmailList.Add(userEmail);
                    }
                }
                if (message.UserGroup != null)
                {
                    var userGroupEmail = (from p in context.MobilePermission
                                          join up in context.MobileUserPermission on p.Id equals up.PermissionId
                                          join u in context.Personel on up.UserId equals u.EmpnPsl
                                          where p.Code == message.UserGroup && u.EmailPsl != null
                                          select u.EmailPsl).ToList();

                    if (userGroupEmail.Count() > 0)
                    {
                        EmailList.Concat(userGroupEmail);
                    }
                }
                if (EmailList.Count() > 0)
                {
                    foreach (var item in EmailList)
                    {
                        SendEmail(item, message.Title, message.Body, null);
                    }
                }

                PushPayload pushPayload = creatPushMessage(message);
                var         test        = client.SendPush(pushPayload);

                message.IsSend = true;
                context.MobilePushMessage.Update(message);
            }
            await context.SaveChangesAsync();

            return;
        }
Exemple #2
0
        /// <summary>
        ///  Insert or Update the sals order
        /// </summary>
        /// <param name="orderInfo"></param>
        /// /// <param name="products"></param>
        /// <returns></returns>
        public async Task <int> InsertSalesOrderByOrderIdAsync(OrderParam orderInfo, List <ProductParam> products)
        {
            string orderId  = orderInfo.title;
            var    oldOrder = await context.Pomst.Where(p => p.PonbPo == orderId).FirstOrDefaultAsync();

            try
            {
                if (oldOrder != null)
                {
                    oldOrder.DatePo   = orderInfo.date.Value.Date;
                    oldOrder.TnamPo   = orderInfo.receiver;
                    oldOrder.TcpyPo   = context.Loctb.Where(p => p.LocnLtb == orderInfo.deptId).Select(p => p.DescLtb).FirstOrDefault();
                    oldOrder.TfaxPo   = orderInfo.faxReceiver;
                    oldOrder.TtelPo   = orderInfo.telReceiver;
                    oldOrder.FnamPo   = orderInfo.sender;
                    oldOrder.FtelPo   = orderInfo.telSender;
                    oldOrder.FfaxPo   = orderInfo.faxSender;
                    oldOrder.Rmk1Po   = orderInfo.descript;
                    oldOrder.RvmkPo   = orderInfo.remarkfeedback;
                    oldOrder.CstmPo   = orderInfo.deptId;
                    oldOrder.CreaPo   = orderInfo.userId;
                    oldOrder.FqryjPo  = orderInfo.messageForAuditor;
                    oldOrder.StatPo   = orderInfo.statusCode.ToString();
                    oldOrder.TypePo   = orderInfo.type;
                    oldOrder.CachetPo = orderInfo.seal; //todo
                    oldOrder.CtovPo   = orderInfo.copyAfterCheck;
                    oldOrder.MrmkPo   = orderInfo.remarkCorrige;
                    oldOrder.RvmkPo   = orderInfo.remarkfeedback;
                    oldOrder.LdatPo   = DateTime.Now;
                    oldOrder.FcpyPo   = orderInfo.entrepriseName;

                    context.Pomst.Update(oldOrder);

                    var productOld = await context.Popart.Where(p => p.PonbPp == orderId).ToListAsync();

                    foreach (Popart p in productOld)
                    {
                        context.Popart.Remove(p);
                    }
                }
                else
                {
                    var recordCreator = await context.PoCntIssue.Where(p => p.TypePci == "PO").FirstOrDefaultAsync();

                    // TODO
                    // orderId = recordCreator.PrfxPci + DateTime.Now.ToString("yyyy") + "-" + context.Popart.Count().ToString("0000");//recordCreator.MaxnPci++
                    recordCreator.YearPci = DateTime.Now.ToString("yyyy");
                    recordCreator.MaxnPci = recordCreator.MaxnPci + 1;
                    context.PoCntIssue.Update(recordCreator);
                    orderId = recordCreator.PrfxPci + recordCreator.YearPci + "-" + Convert.ToInt32(recordCreator.MaxnPci).ToString("0000");
                    Pomst newOrder = new Pomst
                    {
                        PonbPo   = orderId,
                        DatePo   = orderInfo.date.Value.Date,
                        LdatPo   = DateTime.Now,
                        TnamPo   = orderInfo.receiver,
                        TcpyPo   = context.Loctb.Where(p => p.LocnLtb == orderInfo.deptId).Select(p => p.DescLtb).FirstOrDefault(),
                        TfaxPo   = orderInfo.faxReceiver,
                        TtelPo   = orderInfo.telReceiver,
                        FnamPo   = orderInfo.sender,
                        FtelPo   = orderInfo.telSender,
                        FfaxPo   = orderInfo.faxSender,
                        Rmk1Po   = orderInfo.descript,
                        RvmkPo   = orderInfo.remarkfeedback,
                        CstmPo   = orderInfo.deptId,
                        CreaPo   = orderInfo.userId,
                        FqryjPo  = orderInfo.messageForAuditor,
                        StatPo   = orderInfo.statusCode.ToString(),
                        TypePo   = orderInfo.type,
                        CtovPo   = orderInfo.copyAfterCheck,
                        LedtPo   = orderInfo.userId,
                        MrmkPo   = orderInfo.remarkCorrige,
                        CachetPo = orderInfo.seal,// todo: change to the id
                        FcpyPo   = orderInfo.entrepriseName,
                        SpyjPo   = "",
                        FqrPo    = "",
                        CwPo     = "",
                        CwyjPo   = "",
                        JlPo     = "",
                        JlyjPo   = "",
                        CrtdPo   = DateTime.Now,
                        PlntPo   = orderInfo.entrepriseType,
                        CmplPo   = false
                    };
                    context.Pomst.Add(newOrder);
                }
                int index = 1;
                foreach (var product in products)
                {
                    Popart newCargo = new Popart     // Take into the cargo repository
                    {
                        PonbPp  = orderId,
                        OrdrPp  = index.ToString("00"),
                        PartPp  = product.idProduct,
                        DescPp  = await context.Itemmst.Where(p => p.PartIt == product.idProduct).Select(p => p.DescIt).FirstOrDefaultAsync(),//Get from the table data
                        TqtyPp  = product.numberProduct,
                        UnitPp  = product.unitProduct,
                        PricPp  = product.priceProduct,
                        SchdPp  = product.datePayProduct,
                        SumPp   = product.totalPrice,
                        RemkPp  = product.descriptProduct,
                        Desc3Pp = product.nameOffical,
                        PtypPp  = product.unitPriceType,
                        SpecPp  = product.adresseProduct,
                        PlntPp  = product.entrepriseType,
                        LdatPp  = DateTime.Now,
                        LedtPp  = orderInfo.userId,
                        EquivPp = product.equivalenceValue
                    };
                    index++;
                    context.Popart.Add(newCargo);
                }
                await context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                return(1);
            }
            return(0);

            /*productOld.DescPp = product.nameProduct;
             * productOld.TqtyPp = product.numberProduct;
             * productOld.UnitPp = product.unitProduct;   更新模板是使用
             * productOld.PricPp = product.priceProduct;
             * productOld.SchdPp = product.datePayProduct;*/
        }