Example #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 (ForwarderMngEntities context = CreateContext())
                {
                    Forwarder dbItem = context.Forwarder.FirstOrDefault(o => o.ForwarderID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Forwarder not found!";
                        return(false);
                    }
                    else
                    {
                        context.Forwarder.Remove(dbItem);
                        context.SaveChanges();

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

            try
            {
                using (ForwarderMngEntities context = CreateContext())
                {
                    Forwarder dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new Forwarder();
                        context.Forwarder.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.Forwarder.FirstOrDefault(o => o.ForwarderID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Forwarder not found!";
                        return(false);
                    }
                    else
                    {
                        converter.DTO2BD_Forwarder(dtoItem, ref dbItem, this._TempFolder);

                        context.ForwarderImage.Local.Where(o => o.Forwarder == null).ToList().ForEach(o => context.ForwarderImage.Remove(o));
                        context.ForwarderPIC.Local.Where(o => o.Forwarder == null).ToList().ForEach(o => context.ForwarderPIC.Remove(o));

                        context.SaveChanges();

                        dtoItem = GetData(dbItem.ForwarderID, 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 == "ForwarderUDUnique")
                    {
                        notification.Message = "The Forwarder 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);
            }
        }