示例#1
0
 public void DTO2BD(DTO.SubMaterialOptionMng.SubMaterialOption dtoItem, ref SubMaterialOption dbItem)
 {
     AutoMapper.Mapper.Map <DTO.SubMaterialOptionMng.SubMaterialOption, SubMaterialOption>(dtoItem, dbItem);
     dbItem.UpdatedDate = DateTime.Now;
     if (dtoItem.SubMaterialOptionID == 0)
     {
         dbItem.CreatedBy   = dtoItem.CreatedBy;
         dbItem.CreatedDate = DateTime.Now;
     }
 }
示例#2
0
        public override bool UpdateData(int id, ref DTO.SubMaterialOptionMng.SubMaterialOption dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            int    number;
            string indexName;

            try
            {
                using (SubMaterialOptionMngEntities context = CreateContext())
                {
                    SubMaterialOption dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new SubMaterialOption();
                        context.SubMaterialOption.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.SubMaterialOption.FirstOrDefault(o => o.SubMaterialOptionID == id);
                    }

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

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

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

                        dtoItem = GetData(dbItem.SubMaterialOptionID, 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 == "SubMaterialColorUnique")
                    {
                        notification.Message = "The combination of Sub Material and Sub 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);
            }
        }
示例#3
0
        public override bool DeleteData(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (SubMaterialOptionMngEntities context = CreateContext())
                {
                    SubMaterialOption dbItem = context.SubMaterialOption.FirstOrDefault(o => o.SubMaterialOptionID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Sub material option not found!";
                        return(false);
                    }
                    else
                    {
                        // processing image
                        if (!string.IsNullOrEmpty(dbItem.ImageFile))
                        {
                            Library.FileHelper.ImageManager imgMng = new Library.FileHelper.ImageManager(FrameworkSetting.Setting.AbsoluteFileFolder, FrameworkSetting.Setting.AbsoluteThumbnailFolder);

                            // delete phisycal files
                            string toBeDeletedFileLocation      = "";
                            string toBeDeletedThumbnailLocation = "";
                            fwFactory.GetDBFileLocation(dbItem.ImageFile, out toBeDeletedFileLocation, out toBeDeletedThumbnailLocation);

                            if (!string.IsNullOrEmpty(toBeDeletedFileLocation))
                            {
                                try
                                {
                                    imgMng.DeleteFile(toBeDeletedFileLocation);
                                }
                                catch { }
                            }

                            if (!string.IsNullOrEmpty(toBeDeletedThumbnailLocation))
                            {
                                try
                                {
                                    imgMng.DeleteFile(toBeDeletedThumbnailLocation);
                                }
                                catch { }
                            }
                        }

                        context.SubMaterialOption.Remove(dbItem);
                        context.SaveChanges();

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