Ejemplo n.º 1
0
        private void SendNotification(string emailSubject, string emailBody, string sendToEmail, List <int?> UserIDs)
        {
            try
            {
                List <string> emailAddress = new List <string>();

                using (QCReportEntities context = CreateContext())
                {
                    //string sendToEmail = "*****@*****.**";

                    //int userID = 142;

                    // add to NotificationMessage table
                    if (UserIDs.Count > 0)
                    {
                        foreach (var userID in UserIDs)
                        {
                            if (userID != null)
                            {
                                NotificationMessage notification = new NotificationMessage();
                                notification.UserID = userID;
                                notification.NotificationMessageTag     = Module.Framework.ConstantIdentifier.MOBILE_APP_MESSAGE_TAG_QAQC;
                                notification.NotificationMessageTitle   = emailSubject;
                                notification.NotificationMessageContent = emailBody;
                                context.NotificationMessage.Add(notification);
                            }
                        }
                    }

                    EmailNotificationMessage dbEmail = new EmailNotificationMessage();
                    dbEmail.EmailBody    = emailBody;
                    dbEmail.EmailSubject = emailSubject;
                    dbEmail.SendTo       = sendToEmail;
                    context.EmailNotificationMessage.Add(dbEmail);
                    context.SaveChanges();
                }
            }
            catch { }
        }
Ejemplo n.º 2
0
        public bool Update(int userId, int id, ref object dto, out Notification notification)
        {
            DTO.QCReportDTO dtoItem = ((Newtonsoft.Json.Linq.JObject)dto).ToObject <DTO.QCReportDTO>();
            notification = new Notification()
            {
                Type = NotificationType.Success
            };
            try
            {
                using (QCReportEntities context = CreateContext())
                {
                    QCReport dbItem = null;
                    if (id > 0)
                    {
                        dbItem = context.QCReport.FirstOrDefault(s => s.QCReportID == id);

                        if (dbItem == null)
                        {
                            notification = new Notification()
                            {
                                Type = NotificationType.Error, Message = "Can not find data"
                            };
                            return(false);
                        }
                    }
                    else
                    {
                        dbItem = new QCReport();
                        context.QCReport.Add(dbItem);
                    }

                    // add QCReportImage
                    foreach (var item in dtoItem.QCReportImageDTOs)
                    {
                        if (item.ScanHasChange)
                        {
                            if (string.IsNullOrEmpty(item.ScanNewFile))
                            {
                                fwFactory.RemoveFile(item.FileUD);
                            }
                            else
                            {
                                item.FileUD = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", item.ScanNewFile, item.FileUD);
                            }
                        }
                    }

                    converter.DTO2DB_QCReport(dtoItem, ref dbItem);
                    // product image
                    if (dtoItem.ScanHasChange)
                    {
                        dbItem.ProductImage = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoItem.ScanNewFile, dtoItem.ProductImage);
                    }

                    if (dtoItem.ReportScanHasChange)
                    {
                        dbItem.ReportFile = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoItem.ReportScanNewFile, dtoItem.ReportFile);
                    }

                    dbItem.UpdatedBy   = userId;
                    dbItem.UpdatedDate = DateTime.Now;
                    context.QCReportSummary.Local.Where(o => o.QCReport == null).ToList().ForEach(s => context.QCReportSummary.Remove(s));
                    context.QCReportDetail.Local.Where(o => o.QCReport == null).ToList().ForEach(s => context.QCReportDetail.Remove(s));
                    context.QCReportDefect.Local.Where(o => o.QCReport == null).ToList().ForEach(s => context.QCReportDefect.Remove(s));
                    context.QCReportImage.Local.Where(o => o.QCReport == null).ToList().ForEach(s => context.QCReportImage.Remove(s));
                    context.QCReportTestEnvironment.Local.Where(o => o.QCReport == null).ToList().ForEach(s => context.QCReportTestEnvironment.Remove(s));
                    context.QCReportFactoryOrderDetail.Local.Where(o => o.QCReport == null).ToList().ForEach(s => context.QCReportFactoryOrderDetail.Remove(s));
                    context.SaveChanges();

                    //Create code of id
                    dbItem.QCReportUD = "QC" + dbItem.QCReportID.ToString("D8");
                    context.SaveChanges();

                    if (id == 0)
                    {
                        string emailSubject = "";
                        string emailBody    = "";
                        string url          = "";
                        url           = this.frontendURL + "QCReportMng/Edit/" + dbItem.QCReportID.ToString();
                        emailSubject += "New QC report - " + "[" + dtoItem.ClientUD + "]" + " / " + "[" + dtoItem.FactoryUD + "]" + " - " + dtoItem.ArticleCode + " - " + dtoItem.Description;
                        emailBody    += "New QC Report:";
                        emailBody    += Environment.NewLine + "Click <a href='" + url + "'>here</a> to link to QC Report:" + url;

                        var QCReportMenber = context.QCReportMng_QCReportGroupMember_View.ToList();
                        var ClientManager  = context.QCReportMng_ClientManager_View.Where(o => o.ClientID == dtoItem.ClientID).FirstOrDefault();

                        List <int?> UserIDs = new List <int?>();
                        UserIDs.Add(ClientManager.AccManagerID);
                        UserIDs.Add(ClientManager.AccManagerAssitantID);
                        UserIDs.Add(ClientManager.VNMerchandiserID);
                        UserIDs.Add(ClientManager.VNMerchandiserAssitantID);

                        string sendToEmail = "";
                        if (QCReportMenber.Count() > 0)
                        {
                            foreach (var item in QCReportMenber)
                            {
                                if (sendToEmail != "")
                                {
                                    sendToEmail += ";" + item.Email;
                                }
                                else
                                {
                                    sendToEmail = item.Email;
                                }

                                UserIDs.Add(item.UserID);
                            }
                        }
                        if (ClientManager.AccManagerEmail != "")
                        {
                            if (sendToEmail != "")
                            {
                                sendToEmail += ";" + ClientManager.AccManagerEmail;
                            }
                            else
                            {
                                sendToEmail = ClientManager.AccManagerEmail;
                            }
                        }
                        if (ClientManager.AccManagerAssitantEmail != "")
                        {
                            if (sendToEmail != "")
                            {
                                sendToEmail += ";" + ClientManager.AccManagerAssitantEmail;
                            }
                            else
                            {
                                sendToEmail = ClientManager.AccManagerAssitantEmail;
                            }
                        }
                        if (ClientManager.VNMerchandiserEmail != "")
                        {
                            if (sendToEmail != "")
                            {
                                sendToEmail += ";" + ClientManager.VNMerchandiserEmail;
                            }
                            else
                            {
                                sendToEmail = ClientManager.VNMerchandiserEmail;
                            }
                        }
                        if (ClientManager.VNMerchandiserAssitantEmail != "")
                        {
                            if (sendToEmail != "")
                            {
                                sendToEmail += ";" + ClientManager.VNMerchandiserAssitantEmail;
                            }
                            else
                            {
                                sendToEmail = ClientManager.VNMerchandiserAssitantEmail;
                            }
                        }

                        SendNotification(emailSubject, emailBody, sendToEmail, UserIDs);
                    }


                    dto = GetData(dbItem.QCReportID, dbItem.SaleOrderDetailID, dbItem.FactoryID, null, null, null, out notification).Data;
                }
                return(true);
            }
            catch (Exception ex)
            {
                notification = new Notification()
                {
                    Type = NotificationType.Error, Message = ex.Message
                };
                return(false);
            }
        }