예제 #1
0
        public bool Delete(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (EurofarSampleCollectionMngEntities context = CreateContext())
                {
                    SampleProduct dbItem = context.SampleProduct.FirstOrDefault(o => o.SampleProductID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Sample Item not found!";
                        return(false);
                    }
                    else
                    {
                        dbItem.IsEurofarSampleCollection   = false;
                        dbItem.EurofarSampleCollectionBy   = null;
                        dbItem.EurofarSampleCollectionDate = null;
                        context.SaveChanges();

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

                return(false);
            }
        }
예제 #2
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.EurofarSearchDTO>();
            totalRows = 0;

            string client        = null;
            string season        = null;
            string description   = null;
            string sampleOrderUD = null;

            if (filters.ContainsKey("season") && !string.IsNullOrEmpty(filters["season"].ToString()))
            {
                season = filters["season"].ToString().Replace("'", "''");
            }
            if (filters.ContainsKey("client") && !string.IsNullOrEmpty(filters["client"].ToString()))
            {
                client = filters["client"].ToString().Replace("'", "''");
            }
            if (filters.ContainsKey("description") && !string.IsNullOrEmpty(filters["description"].ToString()))
            {
                description = filters["description"].ToString().Replace("'", "''");
            }
            if (filters.ContainsKey("sampleOrderUD") && !string.IsNullOrEmpty(filters["sampleOrderUD"].ToString()))
            {
                sampleOrderUD = filters["sampleOrderUD"].ToString().Replace("'", "''");
            }

            //try to get data
            try
            {
                using (EurofarSampleCollectionMngEntities context = CreateContext())
                {
                    totalRows = context.EurofarSampleCollectionMng_function_SampleProduct(orderBy, orderDirection, client, season, description, sampleOrderUD).Count();
                    var result = context.EurofarSampleCollectionMng_function_SampleProduct(orderBy, orderDirection, client, season, description, sampleOrderUD);
                    data.Data = converter.DB2DTO_EurofarSearchResultList(result.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList());
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }