예제 #1
0
        private bool IsNullPropertiesCushionColor(CushionColor cushionColor, ref string emailBody)
        {
            bool isNotNull = true;

            // Set content notification.
            emailBody += "Cushion Color ID: " + cushionColor.CushionColorID;
            emailBody += Environment.NewLine + "Cushion Color UD: " + cushionColor.CushionColorUD;
            emailBody += Environment.NewLine + "Cushion Color NM: " + cushionColor.CushionColorNM;

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

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

            return(isNotNull);
        }
예제 #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 (CushionColorMngEntities context = CreateContext())
                {
                    CushionColor dbItem = context.CushionColor.FirstOrDefault(o => o.CushionColorID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "CushionColor not found!";
                        return(false);
                    }
                    else
                    {
                        var item = context.CushionColorMng_CushionColorCheck_View.Where(o => o.CushionColorID == id).FirstOrDefault();
                        //CheckPermission
                        if (item.isUsed.Value == true)
                        {
                            throw new Exception("You can't delete because it used in item other!");
                        }
                        context.CushionColor.Remove(dbItem);
                        context.SaveChanges();

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }
        }
예제 #3
0
        public bool UpdateData(int id, ref object dtoItem, int iRequesterID, out Library.DTO.Notification notification)
        {
            notification      = new Notification();
            notification.Type = NotificationType.Success;

            int    number;
            string indexName;

            DTO.CushionColor dtoCushionColor = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.CushionColor>();
            try
            {
                using (var context = CreateContext())
                {
                    CushionColor cushionColor = null;

                    if (id == 0)
                    {
                        dtoCushionColor.CreatedBy = iRequesterID;
                        cushionColor = new CushionColor();

                        context.CushionColor.Add(cushionColor);
                    }
                    else
                    {
                        var item = context.CushionColorMng_CushionColorCheck_View.Where(o => o.CushionColorID == id).FirstOrDefault();
                        //CheckPermission
                        if (item.isUsed.Value == true)
                        {
                            throw new Exception("You can't update because it used in item other!");
                        }
                        dtoCushionColor.UpdatedBy = iRequesterID;
                        cushionColor = context.CushionColor.FirstOrDefault(o => o.CushionColorID == id);
                    }

                    if (cushionColor == null)
                    {
                        notification.Message = "Cushion Color not found!";

                        return(false);
                    }
                    else
                    {
                        // check concurrency
                        if (cushionColor.ConcurrencyFlag != null && !cushionColor.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoCushionColor.ConcurrencyFlag_String)))
                        {
                            notification.Type    = NotificationType.Error;
                            notification.Message = Library.Helper.TEXT_CONCURRENCY_CONFLICT;

                            return(false);
                        }

                        converter.DTO2BD(dtoCushionColor, _TempFolder, ref cushionColor);

                        // processing image
                        if (dtoCushionColor.ImageFile_HasChange)
                        {
                            cushionColor.ImageFile = fwFactory.CreateFilePointer(this._TempFolder, dtoCushionColor.ImageFile_NewFile, dtoCushionColor.ImageFile);
                        }

                        // processing test report file 1
                        if (dtoCushionColor.TestReportFile_HasChange1)
                        {
                            cushionColor.TestReportFile1 = fwFactory.CreateNoneImageFilePointer(this._TempFolder, dtoCushionColor.TestReportFile_NewFile1, dtoCushionColor.TestReportFile1);
                        }

                        // processing test report file 2
                        if (dtoCushionColor.TestReportFile_HasChange2)
                        {
                            cushionColor.TestReportFile2 = fwFactory.CreateNoneImageFilePointer(this._TempFolder, dtoCushionColor.TestReportFile_NewFile2, dtoCushionColor.TestReportFile2);
                        }

                        // processing test report file 3
                        if (dtoCushionColor.TestReportFile_HasChange3)
                        {
                            cushionColor.TestReportFile3 = fwFactory.CreateNoneImageFilePointer(this._TempFolder, dtoCushionColor.TestReportFile_NewFile3, dtoCushionColor.TestReportFile3);
                        }

                        if (id <= 0)
                        {
                            // Generate code.
                            using (var trans = context.Database.BeginTransaction())
                            {
                                context.Database.ExecuteSqlCommand("SELECT * FROM CushionColor WITH (TABLOCKX, HOLDLOCK)");

                                try
                                {
                                    var newCode = context.CushionColorMng_function_GenerateCode().FirstOrDefault();

                                    if (!"**".Equals(newCode))
                                    {
                                        cushionColor.CushionColorUD = newCode;

                                        context.SaveChanges();
                                    }
                                    else
                                    {
                                        notification.Type    = NotificationType.Error;
                                        notification.Message = "Auto generated code exceed maximum option: [ZZ]";
                                    }
                                }
                                catch (Exception ex)
                                {
                                    trans.Rollback();
                                    throw ex;
                                }
                                finally
                                {
                                    trans.Commit();
                                }
                            }
                        }
                        else
                        {
                            context.CushionColorProductGroup.Local.Where(o => o.CushionColor == null).ToList().ForEach(o => context.CushionColorProductGroup.Remove(o));
                            context.CushionColorTestReport.Local.Where(o => o.CushionColor == null).ToList().ForEach(o => context.CushionColorTestReport.Remove(o));

                            context.SaveChanges();
                        }

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

                        if (!IsNullPropertiesCushionColor(cushionColor, ref emailBody))
                        {
                            SendToEmailNotification(context, emailSubject, emailBody);
                        }

                        dtoItem = GetData(cushionColor.CushionColorID, out notification).Data;
                        return(true);
                    }
                }
            }
            catch (DataException exData)
            {
                notification.Type = NotificationType.Error;
                ErrorHelper.DataExceptionParser(exData, out number, out indexName);

                if (number == 2601 && !string.IsNullOrEmpty(indexName))
                {
                    if ("CushionColorUDUnique".Equals(indexName))
                    {
                        notification.Message = "The Cushion Color Code is already exists.";
                    }
                }
                else
                {
                    notification.Message = exData.Message;
                }

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

                return(false);
            }
            //notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success };
            //try
            //{
            //    using (CushionColorMngEntities context = CreateContext())
            //    {
            //        CushionColor dbItem = null;
            //        if (id == 0)
            //        {
            //            dbItem = new CushionColor();
            //            context.CushionColor.Add(dbItem);
            //        }
            //        else
            //        {
            //            dbItem = context.CushionColor.FirstOrDefault(o => o.CushionColorID == id);
            //        }

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

            //            converter.DTO2BD(dtoItem, ref dbItem);
            //            context.SaveChanges();

            //            // processing image
            //            if (dtoItem.ImageFile_HasChange)
            //            {
            //                dbItem.ImageFile = fwFactory.CreateFilePointer(this._TempFolder, dtoItem.ImageFile_NewFile, dtoItem.ImageFile);
            //            }

            //            // processing test report file 1
            //            if (dtoItem.TestReportFile_HasChange1)
            //            {
            //                dbItem.TestReportFile1 = fwFactory.CreateNoneImageFilePointer(this._TempFolder, dtoItem.TestReportFile_NewFile1, dtoItem.TestReportFile1);
            //            }

            //            // processing test report file 2
            //            if (dtoItem.TestReportFile_HasChange2)
            //            {
            //                dbItem.TestReportFile2 = fwFactory.CreateNoneImageFilePointer(this._TempFolder, dtoItem.TestReportFile_NewFile2, dtoItem.TestReportFile2);
            //            }

            //            // processing test report file 3
            //            if (dtoItem.TestReportFile_HasChange3)
            //            {
            //                dbItem.TestReportFile3 = fwFactory.CreateNoneImageFilePointer(this._TempFolder, dtoItem.TestReportFile_NewFile3, dtoItem.TestReportFile3);
            //            }
            //            context.SaveChanges();

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

            //            return true;
            //        }
            //    }
            //}
            //catch (Exception ex)
            //{
            //    notification.Type = Library.DTO.NotificationType.Error;
            //    notification.Message = ex.Message;
            //    return false;
            //}
        }
예제 #4
0
        public void DTO2BD(DTO.CushionColor dtoItem, string tempFolder, ref CushionColor dbItem)
        {
            AutoMapper.Mapper.Map <DTO.CushionColor, CushionColor>(dtoItem, dbItem);
            dbItem.UpdatedDate = DateTime.Now;

            // Tri
            // Add created Cushion Color
            if (dtoItem.CushionColorID == 0)
            {
                dbItem.CreatedBy   = dtoItem.CreatedBy;
                dbItem.CreatedDate = DateTime.Now;
            }

            // map child
            if (dtoItem.CushionColorProductGroups != null)
            {
                // map child rows
                foreach (DTO.CushionColorProductGroup dtoGroup in dtoItem.CushionColorProductGroups)
                {
                    CushionColorProductGroup dbGroup;
                    if (dtoGroup.CushionColorProductGroupID <= 0)
                    {
                        dbGroup = new CushionColorProductGroup();
                        dbItem.CushionColorProductGroup.Add(dbGroup);
                    }
                    else
                    {
                        dbGroup = dbItem.CushionColorProductGroup.FirstOrDefault(o => o.CushionColorProductGroupID == dtoGroup.CushionColorProductGroupID);
                    }

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

            // Mapping cushion color test report
            if (dtoItem.CushionColorTestReports != null)
            {
                foreach (var item in dbItem.CushionColorTestReport.ToArray())
                {
                    if (!dtoItem.CushionColorTestReports.Select(s => s.CushionColorTestReportID).Contains(item.CushionColorTestReportID))
                    {
                        dbItem.CushionColorTestReport.Remove(item);
                    }
                }

                Framework.DAL.DataFactory fwFactory = new Framework.DAL.DataFactory();

                // Mapping cushion color test report rows
                foreach (DTO.CushionColorTestReport dtoCushionColorTestReport in dtoItem.CushionColorTestReports)
                {
                    CushionColorTestReport dbCushionColorTestReport;

                    if (dtoCushionColorTestReport.CushionColorTestReportID <= 0)
                    {
                        dbCushionColorTestReport = new CushionColorTestReport();
                        dbItem.CushionColorTestReport.Add(dbCushionColorTestReport);
                    }
                    else
                    {
                        dbCushionColorTestReport = dbItem.CushionColorTestReport.FirstOrDefault(o => o.CushionColorTestReportID == dtoCushionColorTestReport.CushionColorTestReportID);
                    }

                    if (dbCushionColorTestReport != null)
                    {
                        Mapper.Map <DTO.CushionColorTestReport, CushionColorTestReport>(dtoCushionColorTestReport, dbCushionColorTestReport);

                        if (dtoCushionColorTestReport.File_HasChange.HasValue && dtoCushionColorTestReport.File_HasChange.Value)
                        {
                            dbCushionColorTestReport.FileUD = fwFactory.CreateNoneImageFilePointer(tempFolder, dtoCushionColorTestReport.File_NewFile, dtoCushionColorTestReport.FileUD);
                        }
                    }
                }
            }
        }