Esempio n. 1
0
        private bool IsNullPropertiesBackCushion(BackCushion backCushion, ref string emailBody)
        {
            bool isNotNull = true;

            // Set content notification.
            emailBody += "Back Cushion ID: " + backCushion.BackCushionID;
            emailBody += Environment.NewLine + "Back Cushion UD: " + backCushion.BackCushionUD;
            emailBody += Environment.NewLine + "Back Cushion NM: " + backCushion.BackCushionNM;

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

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

            return(isNotNull);
        }
Esempio n. 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 (BackCushionMngEntities context = CreateContext())
                {
                    BackCushion dbItem = context.BackCushion.FirstOrDefault(o => o.BackCushionID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Back cushion not found!";
                        return(false);
                    }
                    else
                    {
                        context.BackCushion.Remove(dbItem);
                        context.SaveChanges();

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

                return(false);
            }
        }
Esempio n. 3
0
        public void DTO2BD(DTO.BackCushionMng.BackCushion dtoItem, ref BackCushion dbItem)
        {
            AutoMapper.Mapper.Map <DTO.BackCushionMng.BackCushion, BackCushion>(dtoItem, dbItem);
            dbItem.UpdatedDate = DateTime.Now;


            // Tri Add created date for BackCushion
            if (dtoItem.BackCushionID == 0)
            {
                dbItem.CreatedBy   = dtoItem.CreatedBy;
                dbItem.CreatedDate = DateTime.Now;
            }

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

                    if (dbGroup != null)
                    {
                        AutoMapper.Mapper.Map <DTO.BackCushionMng.ProductGroup, BackCushionProductGroup>(dtoGroup, dbGroup);
                    }
                }
            }
        }
Esempio n. 4
0
        public override bool UpdateData(int id, ref DTO.BackCushionMng.BackCushion dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (BackCushionMngEntities context = CreateContext())
                {
                    BackCushion dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new BackCushion();
                        context.BackCushion.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.BackCushion.FirstOrDefault(o => o.BackCushionID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Back cushion 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);
                        // processing image
                        if (dtoItem.ImageFile_HasChange)
                        {
                            dbItem.ImageFile = fwFactory.CreateFilePointer(this._TempFolder, dtoItem.ImageFile_NewFile, dtoItem.ImageFile);
                        }

                        if (id <= 0)
                        {
                            // generate code
                            using (DbContextTransaction scope = context.Database.BeginTransaction())
                            {
                                context.Database.ExecuteSqlCommand("SELECT * FROM BackCushion WITH (TABLOCKX, HOLDLOCK)");
                                try
                                {
                                    var newCode = context.BackCushionMng_function_GenerateCode().FirstOrDefault();
                                    if (newCode != "*")
                                    {
                                        dbItem.BackCushionUD = newCode;
                                    }
                                    else
                                    {
                                        throw new Exception("Auto generated code exceed maximum option: [Z]");
                                    }
                                    context.SaveChanges();
                                }
                                catch (Exception ex)
                                {
                                    throw ex;
                                }
                                finally
                                {
                                    scope.Commit();
                                }
                            }
                        }
                        else
                        {
                            context.SaveChanges();
                        }

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

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

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

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

                return(false);
            }
        }