private bool IsNullPropertiesFrameMaterialOption(FrameMaterialOption frameMaterialOption, ref string emailBody)
        {
            bool isNotNull = true;

            // Set content notification.
            emailBody += "Frame Material Option ID: " + frameMaterialOption.FrameMaterialOptionID;
            emailBody += Environment.NewLine + "Frame Material Option UD: " + frameMaterialOption.FrameMaterialOptionUD;
            emailBody += Environment.NewLine + "Frame Material Option NM: " + frameMaterialOption.FrameMaterialOptionNM;

            // Season is null or not null.
            if (string.IsNullOrEmpty(frameMaterialOption.Season))
            {
                emailBody += Environment.NewLine + "Season: Current value is null.";
                isNotNull  = false;
            }
            else
            {
                emailBody += Environment.NewLine + "Season: " + frameMaterialOption.Season;
            }

            // Image is null or not null.
            if (string.IsNullOrEmpty(frameMaterialOption.ImageFile))
            {
                emailBody += Environment.NewLine + "Image: Current value is null.";
                isNotNull  = false;
            }
            else
            {
                emailBody += Environment.NewLine + "Image: " + frameMaterialOption.ImageFile;
            }

            return(isNotNull);
        }
        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);
            }
        }
        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);
            }
        }
        public void DTO2BD(DTO.FrameMaterialOptionMng.FrameMaterialOption dtoItem, ref FrameMaterialOption dbItem)
        {
            AutoMapper.Mapper.Map <DTO.FrameMaterialOptionMng.FrameMaterialOption, FrameMaterialOption>(dtoItem, dbItem);
            dbItem.UpdatedDate = DateTime.Now;

            if (dbItem.FrameMaterialOptionID == 0)
            {
                dbItem.CreatedBy   = dtoItem.CreatedBy;
                dbItem.CreatedDate = DateTime.Now;
            }

            // map child
            if (dtoItem.ProductGroups != null)
            {
                // map child rows
                foreach (DTO.FrameMaterialOptionMng.ProductGroup dtoGroup in dtoItem.ProductGroups)
                {
                    FrameMaterialOptionProductGroup dbGroup;
                    if (dtoGroup.FrameMaterialOptionProductGroupID <= 0)
                    {
                        dbGroup = new FrameMaterialOptionProductGroup();
                        dbItem.FrameMaterialOptionProductGroup.Add(dbGroup);
                    }
                    else
                    {
                        dbGroup = dbItem.FrameMaterialOptionProductGroup.FirstOrDefault(o => o.FrameMaterialOptionProductGroupID == dtoGroup.FrameMaterialOptionProductGroupID);
                    }

                    if (dbGroup != null)
                    {
                        AutoMapper.Mapper.Map <DTO.FrameMaterialOptionMng.ProductGroup, FrameMaterialOptionProductGroup>(dtoGroup, dbGroup);
                    }
                }
            }

            // map pieces
            if (dtoItem.MaterialOptions != null)
            {
                // check for child rows deleted
                foreach (FrameMaterialOptionMaterialOption dbMaterialOption in dbItem.FrameMaterialOptionMaterialOption.ToArray())
                {
                    if (!dtoItem.MaterialOptions.Select(o => o.FrameMaterialOptionMaterialOptionID).Contains(dbMaterialOption.FrameMaterialOptionMaterialOptionID))
                    {
                        dbItem.FrameMaterialOptionMaterialOption.Remove(dbMaterialOption);
                    }
                }

                // map child rows
                foreach (DTO.FrameMaterialOptionMng.FrameMaterialOptionMaterialOption dtoMaterialOption in dtoItem.MaterialOptions)
                {
                    FrameMaterialOptionMaterialOption dbMaterialOption;
                    if (dtoMaterialOption.FrameMaterialOptionMaterialOptionID <= 0)
                    {
                        dbMaterialOption = new FrameMaterialOptionMaterialOption();
                        dbItem.FrameMaterialOptionMaterialOption.Add(dbMaterialOption);
                    }
                    else
                    {
                        dbMaterialOption = dbItem.FrameMaterialOptionMaterialOption.FirstOrDefault(o => o.FrameMaterialOptionMaterialOptionID == dtoMaterialOption.FrameMaterialOptionMaterialOptionID);
                    }

                    if (dbMaterialOption != null)
                    {
                        AutoMapper.Mapper.Map <DTO.FrameMaterialOptionMng.FrameMaterialOptionMaterialOption, FrameMaterialOptionMaterialOption>(dtoMaterialOption, dbMaterialOption);
                    }
                }
            }
        }