public override bool DeleteData(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (FrameMaterialOptionMngEntities context = CreateContext())
                {
                    FrameMaterialOption dbItem = context.FrameMaterialOption.FirstOrDefault(o => o.FrameMaterialOptionID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Frame material option not found!";
                        return(false);
                    }
                    else
                    {
                        context.FrameMaterialOption.Remove(dbItem);
                        context.SaveChanges();

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }
        }
        private void SendToEmailNotification(FrameMaterialOptionMngEntities 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 notification1 = new NotificationMessage();
                    notification1.UserID = emailAddress.UserID;
                    notification1.NotificationMessageTag     = Module.Framework.ConstantIdentifier.MOBILE_APP_MESSAGE_TAG_PRODUCTDEVELOPMENT;
                    notification1.NotificationMessageTitle   = emailSubject;
                    notification1.NotificationMessageContent = emailBody;
                    context.NotificationMessage.Add(notification1);
                }

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

                context.EmailNotificationMessage.Add(emailNotificationMessage);
                context.SaveChanges();
            }
            catch
            {
                throw;
            }
        }
        public override bool UpdateData(int id, ref DTO.FrameMaterialOptionMng.FrameMaterialOption dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            int    number;
            string indexName;

            try
            {
                using (FrameMaterialOptionMngEntities context = CreateContext())
                {
                    FrameMaterialOption dbItem = null;
                    if (id == 0)
                    {
                        dbItem             = new FrameMaterialOption();
                        dbItem.CreatedBy   = dtoItem.UpdatedBy;
                        dbItem.CreatedDate = System.DateTime.Now;
                        context.FrameMaterialOption.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.FrameMaterialOption.FirstOrDefault(o => o.FrameMaterialOptionID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Frame material option 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);
                        }

                        // save data
                        converter.DTO2BD(dtoItem, ref dbItem);
                        context.FrameMaterialOptionMaterialOption.Local.Where(o => o.FrameMaterialOption == null).ToList().ForEach(o => context.FrameMaterialOptionMaterialOption.Remove(o));
                        dbItem.UpdatedBy   = dtoItem.UpdatedBy;
                        dbItem.UpdatedDate = System.DateTime.Now;
                        context.SaveChanges();

                        // 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 FRAME MATERIAL OPTION]" : "TASK REQUEST [UPDATE FRAME MATERIAL OPTION]";
                        string emailBody    = string.Empty;

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

                        dtoItem = GetData(dbItem.FrameMaterialOptionID, 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 == "IX_FrameMaterialOption")
                    {
                        notification.Message = "The combination of Frame Material and Frame 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);
            }
        }