Esempio n. 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 (ClientCountryMngEntities context = CreateContext())
                {
                    ClientCountry dbItem = context.ClientCountry.FirstOrDefault(o => o.ClientCountryID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "ClientCountry not found!";
                        return(false);
                    }
                    else
                    {
                        context.ClientCountry.Remove(dbItem);
                        context.SaveChanges();

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification = new Library.DTO.Notification()
                {
                    Message = ex.Message
                };
                return(false);
            }
        }
Esempio n. 2
0
        public override bool UpdateData(int id, ref DTO.ClientCountryMng.ClientCountry dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (ClientCountryMngEntities context = CreateContext())
                {
                    ClientCountry dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new ClientCountry();
                        context.ClientCountry.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.ClientCountry.FirstOrDefault(o => o.ClientCountryID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "ClientCountry not found!";
                        return(false);
                    }
                    else
                    {
                        converter.DTO2BD_ClientCountry(dtoItem, ref dbItem);
                        context.SaveChanges();

                        dtoItem = GetData(dbItem.ClientCountryID, out notification).Data;

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification = new Library.DTO.Notification()
                {
                    Message = ex.Message
                };
                return(false);
            }
        }