Example #1
0
        public DTO.EditFormData GetEditData(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.EditFormData data = new DTO.EditFormData();
            data.Data = new DTO.TransportationServiceData();

            //try to get data
            try
            {
                using (TransportationServiceMngEntities context = CreateContext())
                {
                    data.Data = converter.DB2DTO_TransportationService(context.TransportationServiceMng_TransportationService_View.FirstOrDefault(o => o.TransportationServiceID == id));
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }
Example #2
0
        public bool Delete(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (TransportationServiceMngEntities context = CreateContext())
                {
                    TransportationService dbItem = context.TransportationService.FirstOrDefault(o => o.TransportationServiceID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Transportation Service not found!";
                        return(false);
                    }
                    else
                    {
                        context.TransportationService.Remove(dbItem);
                        context.SaveChanges();

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;

                return(false);
            }
        }
Example #3
0
        public DTO.SearchFormData GetDataWithFilters(System.Collections.Hashtable filters, int pageSize, int pageIndex, string orderBy, string orderDirection, out int totalRows, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.SearchFormData data = new DTO.SearchFormData();
            data.Data = new List <DTO.TransportationServiceSearchResultData>();
            totalRows = 0;

            string TransportationServiceNM = null;
            string PlateNumber             = null;
            string DriverName   = null;
            string MobileNumber = null;

            if (filters.ContainsKey("TransportationServiceNM") && !string.IsNullOrEmpty(filters["TransportationServiceNM"].ToString()))
            {
                TransportationServiceNM = filters["TransportationServiceNM"].ToString().Replace("'", "''");
            }
            if (filters.ContainsKey("PlateNumber") && !string.IsNullOrEmpty(filters["PlateNumber"].ToString()))
            {
                PlateNumber = filters["PlateNumber"].ToString().Replace("'", "''");
            }
            if (filters.ContainsKey("DriverName") && !string.IsNullOrEmpty(filters["DriverName"].ToString()))
            {
                DriverName = filters["DriverName"].ToString().Replace("'", "''");
            }
            if (filters.ContainsKey("MobileNumber") && !string.IsNullOrEmpty(filters["MobileNumber"].ToString()))
            {
                MobileNumber = filters["MobileNumber"].ToString().Replace("'", "''");
            }

            //try to get data
            try
            {
                using (TransportationServiceMngEntities context = CreateContext())
                {
                    totalRows = context.TransportationServiceMng_function_SearchTransportationService(TransportationServiceNM, PlateNumber, DriverName, MobileNumber, orderBy, orderDirection).Count();
                    var result = context.TransportationServiceMng_function_SearchTransportationService(TransportationServiceNM, PlateNumber, DriverName, MobileNumber, orderBy, orderDirection);
                    data.Data = converter.DB2DTO_TransportationServiceResultList(result.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList());
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }