コード例 #1
0
        private void SendToEmailNotification(MaterialOptionMngEntities context, string emailSubject, string emailBody)
        {
            try
            {
                string sendToEmail = string.Empty;
                //List<string> emailAddresses = new List<string>();

                // My(AVT)[20] and Thanh(AVT)[74].
                var emailAddresses = context.EmployeeMng_Employee_View.Where(o => o.UserID == 20 || o.UserID == 74).Select(s => new { s.Email1, s.UserID }).ToList();
                foreach (var emailAddress in emailAddresses)
                {
                    if (!string.IsNullOrEmpty(sendToEmail))
                    {
                        sendToEmail += "; ";
                    }

                    sendToEmail += emailAddress;

                    // add to NotificationMessage table
                    NotificationMessage notification = new NotificationMessage();
                    notification.UserID = emailAddress.UserID;
                    notification.NotificationMessageTag     = Module.Framework.ConstantIdentifier.MOBILE_APP_MESSAGE_TAG_PRODUCTDEVELOPMENT;
                    notification.NotificationMessageTitle   = emailSubject;
                    notification.NotificationMessageContent = emailBody;
                    context.NotificationMessage.Add(notification);
                }

                // Create data EmailNotificationMessage.
                EmailNotificationMessage emailNotificationMessage = new EmailNotificationMessage();
                emailNotificationMessage.EmailSubject = emailSubject;
                emailNotificationMessage.EmailBody    = emailBody;
                emailNotificationMessage.SendTo       = sendToEmail;

                context.EmailNotificationMessage.Add(emailNotificationMessage);
                context.SaveChanges();
            }
            catch
            {
                throw;
            }
        }
コード例 #2
0
        public override bool DeleteData(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (MaterialOptionMngEntities context = CreateContext())
                {
                    MaterialOption dbItem = context.MaterialOption.FirstOrDefault(o => o.MaterialOptionID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Material not found!";
                        return(false);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(dbItem.ImageFile))
                        {
                            // remove image
                            fwFactory.RemoveImageFile(dbItem.ImageFile);
                        }

                        context.MaterialOption.Remove(dbItem);
                        context.SaveChanges();

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }
        }
コード例 #3
0
        public override bool UpdateData(int id, ref DTO.MaterialOptionMng.MaterialOption dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            int    number;
            string indexName;

            try
            {
                using (MaterialOptionMngEntities context = CreateContext())
                {
                    MaterialOption dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new MaterialOption();
                        context.MaterialOption.Add(dbItem);
                        dbItem.CreatedBy   = dtoItem.UpdatedBy;
                        dbItem.CreatedDate = DateTime.Now;
                    }
                    else
                    {
                        dbItem             = context.MaterialOption.FirstOrDefault(o => o.MaterialOptionID == id);
                        dbItem.UpdatedBy   = dtoItem.UpdatedBy;
                        dbItem.UpdatedDate = DateTime.Now;
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Material not found!";
                        return(false);
                    }
                    else
                    {
                        // check concurrency
                        if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoItem.ConcurrencyFlag_String)))
                        {
                            throw new Exception(DALBase.Helper.TEXT_CONCURRENCY_CONFLICT);
                        }

                        // process test report
                        foreach (var dtoReport in dtoItem.MaterialOptionTestReports.Where(o => o.TestReportHasChange))
                        {
                            dtoReport.FileUD = fwFactory.CreateNoneImageFilePointer(this._TempFolder, dtoReport.TestReportNewFile, dtoReport.FileUD);
                        }

                        // save data
                        converter.DTO2DB(dtoItem, ref dbItem);

                        context.MaterialOptionTestReport.Local.Where(o => o.MaterialOption == null).ToList().ForEach(o => context.MaterialOptionTestReport.Remove(o));
                        // processing image
                        if (dtoItem.ImageFile_HasChange)
                        {
                            dbItem.ImageFile = fwFactory.CreateFilePointer(this._TempFolder, dtoItem.ImageFile_NewFile, dtoItem.ImageFile);
                        }
                        context.SaveChanges();

                        // Handle notification missing information.
                        string emailSubject = (id == 0) ? "TASK REQUEST [CREATE MATERIAL OPTION]" : "TASK REQUEST [UPDATE MATERIAL OPTION]";
                        string emailBody    = string.Empty;

                        if (!IsNullPropertiesMaterialOption(dbItem, ref emailBody))
                        {
                            SendToEmailNotification(context, emailSubject, emailBody);
                        }

                        dtoItem = GetData(dbItem.MaterialOptionID, out notification).Data;

                        return(true);
                    }
                }
            }
            catch (System.Data.DataException dEx)
            {
                notification.Type = Library.DTO.NotificationType.Error;
                Library.ErrorHelper.DataExceptionParser(dEx, out number, out indexName);
                if (number == 2601 && !string.IsNullOrEmpty(indexName))
                {
                    if (indexName == "MaterialTypeColorUnique")
                    {
                        notification.Message = "The combination of Material, Material Type and Material Color is already exists";
                    }
                }
                else
                {
                    notification.Message = dEx.Message;
                }

                return(false);
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }
        }