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 (ClientCityMngEntities context = CreateContext())
                {
                    ClientCity dbItem = context.ClientCities.FirstOrDefault(o => o.ClientCityID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "ClientCity not found!";
                        return(false);
                    }
                    else
                    {
                        context.ClientCities.Remove(dbItem);
                        context.SaveChanges();

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }
        }
Esempio n. 2
0
        public override bool UpdateData(int id, ref DTO.ClientCityMng.ClientCity dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            int    number;
            string indexName;

            try
            {
                using (ClientCityMngEntities context = CreateContext())
                {
                    ClientCity dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new ClientCity();
                        context.ClientCities.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.ClientCities.FirstOrDefault(o => o.ClientCityID == id);
                    }

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

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

                        return(true);
                    }
                }
            }
            catch (System.Data.DataException dEx)
            {
                notification.Type = Library.DTO.NotificationType.Error;
                Library.ErrorHelper.DataExceptionParser(dEx, out number, out indexName);
                if (number == 2601 && !string.IsNullOrEmpty(indexName))
                {
                    if (indexName == "ClientCityUDUnique")
                    {
                        notification.Message = "The ClientCity Code is already exists";
                    }
                }
                else
                {
                    notification.Message = dEx.Message;
                }

                return(false);
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }
        }
Esempio n. 3
0
 public void DTO2BD_ClientCity(DTO.ClientCityMng.ClientCity dtoItem, ref ClientCity dbItem)
 {
     AutoMapper.Mapper.Map <DTO.ClientCityMng.ClientCity, ClientCity>(dtoItem, dbItem);
 }