예제 #1
0
        public override bool DeleteData(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (DDCMngEntities context = CreateContext())
                {
                    DDC dbItem = context.DDC.FirstOrDefault(o => o.DDCID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "DDC not found!";
                        return(false);
                    }
                    else
                    {
                        context.DDC.Remove(dbItem);
                        context.SaveChanges();

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

                return(false);
            }
        }
예제 #2
0
        public override bool UpdateData(int id, ref DTO.DDCMng.DDC dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (DDCMngEntities context = CreateContext())
                {
                    DDC dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new DDC();
                        context.DDC.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.DDC.FirstOrDefault(o => o.DDCID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "DDC not found!";
                        return(false);
                    }
                    else
                    {
                        converter.DTO2BD(dtoItem, ref dbItem);
                        context.DDCDetail.Local.Where(o => o.DDC == null).ToList().ForEach(o => context.DDCDetail.Remove(o));
                        context.SaveChanges();

                        dtoItem = GetData(dbItem.DDCID, string.Empty, out notification).Data;

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

                return(false);
            }
        }