Example #1
0
        public override bool UpdateData(int id, ref DTO.ShowroomItemMng.ShowroomItem dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (ShowroomItemMngEntities context = CreateContext())
                {
                    ShowroomItem dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new ShowroomItem();
                        context.ShowroomItem.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.ShowroomItem.FirstOrDefault(o => o.ShowroomItemID == id);
                    }

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

                        //convert dto to db
                        converter.DTO2DB_ShowroomItem(dtoItem, ref dbItem, this._TempFolder);
                        //save data
                        context.SaveChanges();
                        //generate ArticleCode
                        context.ShowroomItemMng_function_GenerateCode(dbItem.ShowroomItemID);
                        //get return data
                        dtoItem = GetData(dbItem.ShowroomItemID, out notification).Data;
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                notification.DetailMessage.Add(ex.Message);
                if (ex.GetBaseException() != null)
                {
                    notification.DetailMessage.Add(ex.GetBaseException().Message);
                }
                return(false);
            }
        }
Example #2
0
 public void DTO2DB_ShowroomItem(DTO.ShowroomItemMng.ShowroomItem dtoItem, ref ShowroomItem dbItem, string tempFolder)
 {
     if (dtoItem.ImageFile_HasChange.HasValue && dtoItem.ImageFile_HasChange.Value)
     {
         dtoItem.ImageFile = fwFactory.CreateFilePointer(tempFolder, dtoItem.ImageFile_NewFile, dtoItem.ImageFile);
     }
     AutoMapper.Mapper.Map <DTO.ShowroomItemMng.ShowroomItem, ShowroomItem>(dtoItem, dbItem);
     if (dtoItem.ShowroomItemID > 0)
     {
         dbItem.UpdatedDate = DateTime.Now;
         dbItem.UpdatedBy   = dtoItem.UpdatedBy;
     }
     else
     {
         dbItem.CreatedDate = DateTime.Now;
         dbItem.CreatedBy   = dtoItem.UpdatedBy;
     }
 }