Exemple #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 (PODMngEntities context = CreateContext())
         {
             POD dbItem = context.POD.FirstOrDefault(o => o.PoDID == id);
             if (dbItem == null)
             {
                 notification.Message = "POD not found!";
                 return(false);
             }
             else
             {
                 context.POD.Remove(dbItem);
                 context.SaveChanges();
                 return(true);
             }
         }
     }
     catch (Exception ex)
     {
         notification.Type    = Library.DTO.NotificationType.Error;
         notification.Message = ex.Message;
         return(false);
     }
 }
Exemple #2
0
 public void DB2DTO_POD(DTO.PODMng.POD dtoItem, ref POD dbItem)
 {
     AutoMapper.Mapper.Map <DTO.PODMng.POD, POD>(dtoItem, dbItem);
 }
Exemple #3
0
        public override bool UpdateData(int id, ref DTO.PODMng.POD dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            int    number;
            string indexName;

            try
            {
                using (PODMngEntities context = CreateContext())
                {
                    POD dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new POD();
                        context.POD.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.POD.FirstOrDefault(o => o.PoDID == id);
                    }
                    if (dbItem == null)
                    {
                        notification.Message = "POD not found";
                        return(false);
                    }
                    else
                    {
                        converter.DB2DTO_POD(dtoItem, ref dbItem);
                        context.SaveChanges();
                        dtoItem = GetData(dbItem.PoDID, 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 == "PoDUDUniqe")
                    {
                        notification.Message = "The POD 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);
            }
        }