public string AddRecyclingCenter(XElement input)
        {
            try
            {
                RecycleCenter center = new RecycleCenter()
                {
                    Location = input.Element("Location").Value,
                    Comments = input.Element("Comments").Value,
                    Automotive = bool.Parse(input.Element("Automotive").Value),
                    Electronics = bool.Parse(input.Element("Electronics").Value),
                    Construction = bool.Parse(input.Element("Construction").Value),
                    Batteries = bool.Parse(input.Element("Batteries").Value),
                    Garden = bool.Parse(input.Element("Garden").Value),
                    Glass = bool.Parse(input.Element("Glass").Value),
                    Hazardous = bool.Parse(input.Element("Hazardous").Value),
                    Household = bool.Parse(input.Element("Household").Value),
                    Metal = bool.Parse(input.Element("Metal").Value),
                    Paint = bool.Parse(input.Element("Paint").Value),
                    Paper = bool.Parse(input.Element("Paper").Value),
                    Plastic = bool.Parse(input.Element("Plastic").Value),
                    UserId = int.Parse(input.Element("UserId").Value)
                };
                string errorMessage;

                int recycleId = RecyclingDAO.AddRecycleCenter(center, out errorMessage);

                return "Recycling Center addition was " + (recycleId > 0 ? "successful." : ("unsuccessful. Reason: " + errorMessage));
            }
            catch (Exception e)
            {
                return String.Format("Recycling Center addition was unsuccessful. Reason: {0}", e.Message);
            }
        }
Exemple #2
0
        /// <summary>
        /// Adds a new Recycle Center to the database.
        /// </summary>
        /// <param name="center">Recycle Center to add to the database.</param>
        /// <returns>Primary Key (ID) of the newly added Recycle Center.</returns>
        public static int AddRecycleCenter(RecycleCenter center, out string errorMessage)
        {
            try
            {
                using (SqlConnection connection = ConnectionManager.GetConnection())
                {
                    errorMessage = String.Empty;

                    var data = new ActivEarthDataProvidersDataContext(connection);
                    var centerData = new RecyclingCenterDataProvider
                    {
                        location = center.Location,
                        comments = center.Comments,
                        automotive = center.Automotive,
                        electronics = center.Electronics,
                        construction = center.Construction,
                        batteries = center.Batteries,
                        garden = center.Garden,
                        glass = center.Glass,
                        hazardous = center.Hazardous,
                        household = center.Household,
                        metal = center.Metal,
                        paint = center.Paint,
                        paper = center.Paper,
                        plastic = center.Plastic,
                        user_id = center.UserId
                    };

                    data.RecyclingCenterDataProviders.InsertOnSubmit(centerData);
                    data.SubmitChanges();

                    return centerData.id;
                }
            }
            catch (Exception e)
            {
                errorMessage = e.Message;
                return 0;
            }
        }