Beispiel #1
0
 public override bool DeleteData(int id, out Library.DTO.Notification notification)
 {
     notification = new Library.DTO.Notification {
         Type = Library.DTO.NotificationType.Success, Message = "Delete success"
     };
     try
     {
         using (ShowroomAreaMngEntities context = CreateContext())
         {
             var dbItem = context.ShowroomArea.Where(o => o.ShowroomAreaID == id).FirstOrDefault();
             if (dbItem == null)
             {
                 notification.Message = "Deleted not success. Data not found";
                 return(false);
             }
             else
             {
                 context.ShowroomArea.Remove(dbItem);
                 context.SaveChanges();
                 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);
     }
 }
Beispiel #2
0
        public override bool UpdateData(int id, ref DTO.ShowroomAreaMng.ShowroomArea dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (ShowroomAreaMngEntities context = CreateContext())
                {
                    ShowroomArea dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new ShowroomArea();
                        context.ShowroomArea.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.ShowroomArea.FirstOrDefault(o => o.ShowroomAreaID == 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_ShowroomArea(dtoItem, ref dbItem, this._TempFolder);
                        //reove orphan
                        context.ShowroomAreaImage.Local.Where(o => o.ShowroomArea == null).ToList().ForEach(o => context.ShowroomAreaImage.Remove(o));
                        //save data
                        context.SaveChanges();
                        //get return data
                        dtoItem = GetData(dbItem.ShowroomAreaID, 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);
            }
        }