public DTO.PLCMng.EditFormData GetData(int id, int bookingID, int factoryID, int offerLineID, int offerLineSparepartID, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.PLCMng.EditFormData data = new DTO.PLCMng.EditFormData();
            data.Data           = new DTO.PLCMng.PLC();
            data.Data.PLCImages = new List <DTO.PLCMng.PLCImage>();
            data.PLCImageTypes  = new List <DTO.Support.PLCImageType>();

            //try to get data
            try
            {
                using (PLCMngEntities context = CreateContext())
                {
                    // add new case
                    if (id == 0)
                    {
                        PLCMng_ItemForCreatePLC_View dbInfo = null;
                        if (offerLineID > 0)
                        {
                            dbInfo = context.PLCMng_ItemForCreatePLC_View.Where(o => o.BookingID == bookingID && o.FactoryID == factoryID && o.OfferLineID == offerLineID).FirstOrDefault();
                        }
                        else
                        {
                            dbInfo = context.PLCMng_ItemForCreatePLC_View.Where(o => o.BookingID == bookingID && o.FactoryID == factoryID && o.OfferLineSparepartID == offerLineSparepartID).FirstOrDefault();
                        }

                        if (dbInfo != null)
                        {
                            data.Data           = converter.Merge(dbInfo);
                            data.Data.PLCImages = new List <DTO.PLCMng.PLCImage>();
                        }
                        else
                        {
                            throw new Exception("Item not exists!");
                        }
                    }
                    else
                    {
                        data.Data = converter.DB2DTO_PLC(context.PLCMng_PLC_View.Include("PLCMng_PLCImage_View").FirstOrDefault(o => o.PLCID == id));
                    }

                    data.PLCImageTypes = supportFactory.GetPLCImageTypes();
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }
 public DTO.PLCMng.PLC Merge(PLCMng_ItemForCreatePLC_View dbItem)
 {
     return(AutoMapper.Mapper.Map <PLCMng_ItemForCreatePLC_View, DTO.PLCMng.PLC>(dbItem));
 }