コード例 #1
0
        private bool IsNullPropertiesSeatCushion(SeatCushion seatCushion, ref string emailBody)
        {
            bool isNotNull = true;

            // Set content notification.
            emailBody += "Seat Cushion ID: " + seatCushion.SeatCushionID;
            emailBody += Environment.NewLine + "Seat Cushion UD: " + seatCushion.SeatCushionUD;
            emailBody += Environment.NewLine + "Seat Cushion NM: " + seatCushion.SeatCushionNM;

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

            // Image is null or not null.
            if (string.IsNullOrEmpty(seatCushion.ImageFile))
            {
                emailBody += Environment.NewLine + "Image: Current value is null.";
                isNotNull  = false;
            }
            else
            {
                emailBody += Environment.NewLine + "Image: " + seatCushion.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 (SeatCushionMngEntities context = CreateContext())
                {
                    SeatCushion dbItem = context.SeatCushion.FirstOrDefault(o => o.SeatCushionID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Back cushion not found!";
                        return(false);
                    }
                    else
                    {
                        context.SeatCushion.Remove(dbItem);
                        context.SaveChanges();

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

                return(false);
            }
        }
コード例 #3
0
        public void DTO2BD(DTO.SeatCushionMng.SeatCushion dtoItem, ref SeatCushion dbItem)
        {
            AutoMapper.Mapper.Map <DTO.SeatCushionMng.SeatCushion, SeatCushion>(dtoItem, dbItem);
            dbItem.UpdatedDate = DateTime.Now;

            // Tri Add created date for the Seat Cushion
            if (dtoItem.SeatCushionID == 0)
            {
                dbItem.CreatedBy   = dtoItem.CreatedBy;
                dbItem.CreatedDate = DateTime.Now;
            }

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

                    if (dbGroup != null)
                    {
                        AutoMapper.Mapper.Map <DTO.SeatCushionMng.ProductGroup, SeatCushionProductGroup>(dtoGroup, dbGroup);
                    }
                }
            }
        }
コード例 #4
0
        public override bool UpdateData(int id, ref DTO.SeatCushionMng.SeatCushion dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (SeatCushionMngEntities context = CreateContext())
                {
                    SeatCushion dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new SeatCushion();
                        context.SeatCushion.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.SeatCushion.FirstOrDefault(o => o.SeatCushionID == 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 SeatCushion WITH (TABLOCKX, HOLDLOCK)");
                                try
                                {
                                    var newCode = context.SeatCushionMng_function_GenerateCode().FirstOrDefault();
                                    if (newCode != "*")
                                    {
                                        dbItem.SeatCushionUD = 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 SEAT CUSHION]" : "TASK REQUEST [UPDATE SEAT CUSHION]";
                        string emailBody    = string.Empty;

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

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

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

                return(false);
            }
        }