Esempio n. 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);
            }
        }