Example #1
0
        public string GeneralRequest(RequestsModel myRequest)
        {
            GenericInitialization gen = new GenericInitialization();

            try
            {
                using (gen.sqlConnection = new SqlConnection(gen.connectionString))
                {
                    gen.sqlConnection.Open();
                    gen.queryString = "INSERT INTO [ReachHelp].[dbo].[My_Requests] ([Category_Id] ,[Sub_Category_Id] ,[Requested_By] ,[Quantity] ,[Unit] ,[Expected_Date] ,[Delivery_Address] ,[Status]) VALUES(@categoryId,@subCategoryId,@requestedBy,@quantity,@unit,@expectedDate,@deliveryAddress,@postedStatus);SELECT IDENT_CURRENT('[ReachHelp].[dbo].[My_Requests]') AS Request_Id";
                    using (gen.sqlCommand = new SqlCommand(gen.queryString, gen.sqlConnection))
                    {
                        gen.sqlCommand.Parameters.AddWithValue("@categoryId", myRequest.requestCategoryId);
                        gen.sqlCommand.Parameters.AddWithValue("@subCategoryId", myRequest.requestSubCategoryId);
                        gen.sqlCommand.Parameters.AddWithValue("@requestedBy", myRequest.requestedById);
                        gen.sqlCommand.Parameters.AddWithValue("@quantity", myRequest.requestQuantity);
                        gen.sqlCommand.Parameters.AddWithValue("@expectedDate", myRequest.requestExpectedDate);
                        gen.sqlCommand.Parameters.AddWithValue("@unit", myRequest.requestUnit);
                        gen.sqlCommand.Parameters.AddWithValue("@deliveryAddress", myRequest.requestDeliveryAddress);
                        gen.sqlCommand.Parameters.AddWithValue("@postedStatus", "Pending"); // Any new request is pending in the beginning

                        using (gen.sqlDataReader = gen.sqlCommand.ExecuteReader())
                        {
                            while (gen.sqlDataReader.Read())
                            {
                                return(gen.sqlDataReader["Request_Id"].ToString());
                            }
                        }
                    }
                }
            }
            catch (SqlException ex)
            {
                return("-1");
            }
            catch (Exception ex)
            {
                return("-1");
            }
            return("-1");
        }
Example #2
0
        public bool MakeRequest(RequestsModel myRequest)
        {
            GenericInitialization gen = new GenericInitialization();

            try
            {
                using (gen.sqlConnection = new SqlConnection(gen.connectionString))
                {
                    gen.sqlConnection.Open();
                    gen.queryString = "INSERT INTO [ReachHelp].[dbo].[My_Requests] ([Category_Id] ,[Sub_Category_Id] ,[Requested_By] ,[Quantity] ,[Unit] ,[Expected_Date] ,[Delivery_Address] ,[Status]) VALUES(@categoryId,@subCategoryId,@requestedBy,@quantity,@unit,@expectedDate,@deliveryAddress,@postedStatus)";
                    using (gen.sqlCommand = new SqlCommand(gen.queryString, gen.sqlConnection))
                    {
                        gen.sqlCommand.Parameters.AddWithValue("@categoryId", myRequest.requestCategoryId);
                        gen.sqlCommand.Parameters.AddWithValue("@subCategoryId", myRequest.requestSubCategoryId);
                        gen.sqlCommand.Parameters.AddWithValue("@requestedBy", myRequest.requestedById);
                        gen.sqlCommand.Parameters.AddWithValue("@quantity", myRequest.requestQuantity);
                        gen.sqlCommand.Parameters.AddWithValue("@expectedDate", myRequest.requestExpectedDate);
                        gen.sqlCommand.Parameters.AddWithValue("@unit", myRequest.requestUnit);
                        gen.sqlCommand.Parameters.AddWithValue("@deliveryAddress", myRequest.requestDeliveryAddress);
                        gen.sqlCommand.Parameters.AddWithValue("@postedStatus", "Pending"); // Any new request is pending in the beginning

                        if (gen.sqlCommand.ExecuteNonQuery() > 0)
                        {
                            return(true);
                        }
                    }
                }
            }
            catch (SqlException ex)
            {
                return(false);
            }
            catch (Exception ex)
            {
                return(false);
            }
            return(false);
        }
Example #3
0
        public bool RespondToRequest(RequestsModel requestResponse)
        {
            GenericInitialization gen   = new GenericInitialization();
            MessagingModel        email = new MessagingModel();

            try
            {
                using (gen.sqlConnection = new SqlConnection(gen.connectionString))
                {
                    gen.sqlConnection.Open();
                    gen.queryString = "IF NOT EXISTS(SELECT Mapping_Id FROM [ReachHelp].[dbo].[Offer_Request_Mapping] WHERE Request_Id=@requestId AND Offer_Id=@offerId) INSERT INTO [ReachHelp].[dbo].[Offer_Request_Mapping](Offer_Id,Request_Id,[Responded_Quantity],[Responded_Unit],[Status],[Responded_Date]) VALUES(@offerId,@requestId,@respondedQuantity,@respondedUnit,@status,GETDATE()); ELSE	UPDATE [ReachHelp].[dbo].[Offer_Request_Mapping] SET [Responded_Date]=GETDATE(),[Responded_Quantity]=@respondedQuantity,[Responded_Unit]=@respondedUnit,[Status]=CASE WHEN @status='Reject' THEN 'Rejected' WHEN @status='Respond' THEN 'Respond' ELSE [Status] END WHERE Request_Id=@requestId AND Offer_Id=@offerId; UPDATE [ReachHelp].[dbo].[My_Requests] SET [Status] = CASE WHEN @status = 'Reject' THEN 'Pending' ELSE 'Respond' END  WHERE My_Request_Id=@requestId";
                    using (gen.sqlCommand = new SqlCommand(gen.queryString, gen.sqlConnection))
                    {
                        gen.sqlCommand.Parameters.AddWithValue("@requestId", requestResponse.requestId);
                        gen.sqlCommand.Parameters.AddWithValue("@offerId", requestResponse.offerId);
                        gen.sqlCommand.Parameters.AddWithValue("@respondedQuantity", requestResponse.requestQuantity);
                        gen.sqlCommand.Parameters.AddWithValue("@respondedUnit", requestResponse.requestUnit);
                        gen.sqlCommand.Parameters.AddWithValue("@status", requestResponse.requestStatus);
                        if (gen.sqlCommand.ExecuteNonQuery() > 0)
                        {
                            email.TriggerEmail(GetRequestorDetails(requestResponse.requestId), "Response for your request", "<!DOCTYPE html><html> <head> <meta charset=\"utf-8\"> </head> <body> <p> Dear User, </p><br><p> A response has been made for your request. Kindly Login to <a href=\"http://reachelp.in\">ReachHelp<a> to respond. </p></body></html>");
                            return(true);
                        }
                    }
                }
            }
            catch (SqlException ex)
            {
                return(false);
            }
            catch (Exception ex)
            {
                return(false);
            }
            return(false);
        }